perf: short-circuit granted mic permission checks

This commit is contained in:
Edison Jwa
2026-05-24 20:54:49 +09:00
parent 9b8d812f9c
commit b494f8902d
3 changed files with 124 additions and 8 deletions
@@ -371,8 +371,8 @@ void main() {
});
test(
'SWE4-UV-041 / SDD-106 §1: ensureRecordAudio() resolves from the '
'platform return value even when the resolved state is unchanged',
'SWE4-UV-041 / SDD-106 §1: ensureRecordAudio() short-circuits when '
'the cached state is already granted',
() async {
final svc = AndroidPermissionsService(channel: channel)..start();
@@ -392,7 +392,7 @@ void main() {
expect(result, AndroidRecordAudioPermissionState.granted);
expect(
outgoingCalls.where((c) => c.method == methodRequestRecordAudio),
hasLength(1),
isEmpty,
);
svc.dispose();
},
@@ -411,6 +411,46 @@ void main() {
svc.dispose();
});
test('startup permissions request emits outbound method and records '
'multiple returned states', () async {
final svc = AndroidPermissionsService(channel: channel)..start();
outgoingResponder = (call) async {
if (call.method == methodRequestStartupPermissions) {
return {
'android.permission.RECORD_AUDIO': 'Granted',
'android.permission.BLUETOOTH_CONNECT': 'Denied',
'android.permission.POST_NOTIFICATIONS': 'PermanentlyDenied',
};
}
return null;
};
final result = await svc.ensureStartupPermissions();
expect(
outgoingCalls.where((c) => c.method == methodRequestStartupPermissions),
hasLength(1),
);
expect(
result[AndroidPermissionKind.recordAudio],
AndroidRecordAudioPermissionState.granted,
);
expect(
result[AndroidPermissionKind.bluetoothConnect],
AndroidRecordAudioPermissionState.denied,
);
expect(
result[AndroidPermissionKind.postNotifications],
AndroidRecordAudioPermissionState.permanentlyDenied,
);
expect(
svc.permissionState(AndroidPermissionKind.bluetoothConnect).value,
AndroidRecordAudioPermissionState.denied,
);
svc.dispose();
});
test('SWE4-UV-041 / SDD-106: non-Android short-circuit — when channel '
'is null, recordAudioState seeds to granted and ensureRecordAudio '
'resolves synchronously without touching any channel', () async {