Plezy declares appCategory="video", so on Android Automotive OS it is a parked app bound by car app quality DD-2/DD-3: audio must stop when the vehicle starts driving and must not be resumable while driving. Two paths kept audio alive. Music playback ran under a mediaPlayback foreground service whose lifecycle observer was registered for Apple TV only, so it never paused when Android backgrounded the app. Video pausing hung off AppLifecycleState.hidden, which Flutter only synthesizes once Android delivers onStop; a car without the Automotive compatibility mode delivers onPause alone, which maps to AppLifecycleState.inactive and the player ignored. Gate every path that can start audio on a new lifecycle predicate, automotivePlaybackAllowed, which permits playback on a car only while the app is resumed and fails closed on an unknown lifecycle state. That covers explicit play, gapless arming and track transitions, live retry and channel switch, frame-rate-match resume, VOD/live startup, and the queue navigation commands of the OS media session, plus a last-resort pause for when the platform player resumes itself on native audio-focus regain. Playback authority on the media-session router is deliberately left alone: the router consumes a denied event, so gating it would swallow PauseEvent and leave the OS unable to stop audio. Reacting to lifecycle callbacks is the mechanism the platform documents as sufficient, so no android.car dependency is added. The music queue no longer requests POST_NOTIFICATIONS on a car, where the foreground service and its notification never start: there is nothing to authorize, and the prompt would take focus and make the gate discard the first play intent. Detect the form factor too: FEATURE_AUTOMOTIVE now vetoes the Android TV verdict, so a rotary-only head unit no longer inherits the leanback experience. Picture-in-picture is gated on FEATURE_PICTURE_IN_PICTURE, which cars lack, so the app's UI cannot stay on screen while driving, and nothing forces a preferred orientation on a fixed-orientation display.
117 lines
3.9 KiB
Dart
117 lines
3.9 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:plezy/utils/platform_detector.dart';
|
|
|
|
void main() {
|
|
setUp(() {
|
|
TvDetectionService.debugReset();
|
|
addTearDown(TvDetectionService.debugReset);
|
|
});
|
|
|
|
test('concurrent callers wait for TV detection', () async {
|
|
final detection = Completer<void>();
|
|
TvDetectionService.debugDetectionGate = detection.future;
|
|
|
|
final first = TvDetectionService.getInstance(forceTv: true);
|
|
var secondCompleted = false;
|
|
final second = TvDetectionService.getInstance();
|
|
unawaited(second.then((_) => secondCompleted = true));
|
|
await Future<void>.delayed(Duration.zero);
|
|
|
|
expect(secondCompleted, isFalse);
|
|
detection.complete();
|
|
|
|
final instances = await Future.wait([first, second]);
|
|
expect(identical(instances.first, instances.last), isTrue);
|
|
expect(instances.first.isTV, isTrue);
|
|
});
|
|
|
|
group('detectAndroidTvFromSystemFeatures', () {
|
|
test('detects leanback devices', () {
|
|
final detection = detectAndroidTvFromSystemFeatures([
|
|
'android.software.leanback',
|
|
'android.hardware.touchscreen',
|
|
]);
|
|
|
|
expect(detection.isTv, isTrue);
|
|
expect(detection.reasons, contains('leanback'));
|
|
expect(detection.reasons, isNot(contains('no_touchscreen')));
|
|
});
|
|
|
|
test('detects Fire TV even when touchscreen is present', () {
|
|
final detection = detectAndroidTvFromSystemFeatures(['amazon.hardware.fire_tv', 'android.hardware.touchscreen']);
|
|
|
|
expect(detection.isTv, isTrue);
|
|
expect(detection.reasons, contains('fire_tv'));
|
|
expect(detection.reasons, isNot(contains('no_touchscreen')));
|
|
});
|
|
|
|
test('detects devices without real touchscreen capability', () {
|
|
final detection = detectAndroidTvFromSystemFeatures(['android.hardware.faketouch']);
|
|
|
|
expect(detection.isTv, isTrue);
|
|
expect(detection.reasons, contains('no_touchscreen'));
|
|
});
|
|
|
|
test('detects television feature', () {
|
|
final detection = detectAndroidTvFromSystemFeatures([
|
|
'android.hardware.type.television',
|
|
'android.hardware.touchscreen',
|
|
]);
|
|
|
|
expect(detection.isTv, isTrue);
|
|
expect(detection.reasons, contains('television_feature'));
|
|
});
|
|
|
|
test('does not classify touchscreen-only devices as TV', () {
|
|
final detection = detectAndroidTvFromSystemFeatures(['android.hardware.touchscreen']);
|
|
|
|
expect(detection.isTv, isFalse);
|
|
expect(detection.reasons, isEmpty);
|
|
});
|
|
|
|
test('does not classify empty feature lists as no-touchscreen TVs', () {
|
|
final detection = detectAndroidTvFromSystemFeatures(const []);
|
|
|
|
expect(detection.isTv, isFalse);
|
|
expect(detection.reasons, isEmpty);
|
|
});
|
|
|
|
test('classifies automotive head units as cars, not TVs', () {
|
|
final detection = detectAndroidTvFromSystemFeatures([
|
|
'android.hardware.type.automotive',
|
|
'android.hardware.touchscreen',
|
|
]);
|
|
|
|
expect(detection.isAutomotive, isTrue);
|
|
expect(detection.isTv, isFalse);
|
|
});
|
|
|
|
test('rotary-only head units are cars despite reporting no touchscreen', () {
|
|
final detection = detectAndroidTvFromSystemFeatures(['android.hardware.type.automotive']);
|
|
|
|
expect(detection.isAutomotive, isTrue);
|
|
expect(detection.isTv, isFalse);
|
|
expect(detection.reasons, contains('no_touchscreen'));
|
|
});
|
|
|
|
test('automotive vetoes a stray leanback flag from an OEM image', () {
|
|
final detection = detectAndroidTvFromSystemFeatures([
|
|
'android.hardware.type.automotive',
|
|
'android.software.leanback',
|
|
'android.hardware.touchscreen',
|
|
]);
|
|
|
|
expect(detection.isAutomotive, isTrue);
|
|
expect(detection.isTv, isFalse);
|
|
});
|
|
|
|
test('ordinary devices are not automotive', () {
|
|
final detection = detectAndroidTvFromSystemFeatures(['android.hardware.touchscreen']);
|
|
|
|
expect(detection.isAutomotive, isFalse);
|
|
});
|
|
});
|
|
}
|