fix(android): unblock mic permission startup
This commit is contained in:
@@ -131,10 +131,11 @@ class AndroidPermissionsService {
|
||||
/// production code uses the default channel keyed on
|
||||
/// [androidPermissionsChannelName].
|
||||
AndroidPermissionsService({MethodChannel? channel})
|
||||
: _channel = channel ??
|
||||
(_isAndroid
|
||||
? const MethodChannel(androidPermissionsChannelName)
|
||||
: null);
|
||||
: _channel =
|
||||
channel ??
|
||||
(_isAndroid
|
||||
? const MethodChannel(androidPermissionsChannelName)
|
||||
: null);
|
||||
|
||||
/// Platform-detection seam. Web counts as non-Android.
|
||||
static bool get _isAndroid {
|
||||
@@ -148,13 +149,13 @@ class AndroidPermissionsService {
|
||||
|
||||
final ValueNotifier<AndroidRecordAudioPermissionState> _state =
|
||||
ValueNotifier<AndroidRecordAudioPermissionState>(
|
||||
// On non-Android, present as granted so the voice-join gate is a
|
||||
// no-op (desktop / iOS have separate audio-permission paths owned
|
||||
// elsewhere; see SDD-101 for iOS).
|
||||
_isAndroid
|
||||
? AndroidRecordAudioPermissionState.unknown
|
||||
: AndroidRecordAudioPermissionState.granted,
|
||||
);
|
||||
// On non-Android, present as granted so the voice-join gate is a
|
||||
// no-op (desktop / iOS have separate audio-permission paths owned
|
||||
// elsewhere; see SDD-101 for iOS).
|
||||
_isAndroid
|
||||
? AndroidRecordAudioPermissionState.unknown
|
||||
: AndroidRecordAudioPermissionState.granted,
|
||||
);
|
||||
|
||||
bool _started = false;
|
||||
|
||||
@@ -214,16 +215,14 @@ class AndroidPermissionsService {
|
||||
if (ch == null) {
|
||||
return AndroidRecordAudioPermissionState.granted;
|
||||
}
|
||||
// Snapshot the pre-invocation state. If the platform synchronously
|
||||
// resolves the request to a NEW state during invokeMethod (the
|
||||
// platform may emit permissionStateChanged before invokeMethod
|
||||
// returns), we can return immediately. If the state is unchanged
|
||||
// (typical: user is being re-prompted after a previous denial; the
|
||||
// platform always re-prompts and the resolution arrives
|
||||
// asynchronously), we must wait for the next listener fire.
|
||||
// Snapshot the pre-invocation state. New Android hosts return the
|
||||
// resolved Kotlin PermissionState string from requestRecordAudio;
|
||||
// older/test hosts may still return null and rely only on the
|
||||
// permissionStateChanged callback below.
|
||||
final preInvokeState = _state.value;
|
||||
String? returnedState;
|
||||
try {
|
||||
await ch.invokeMethod<void>(methodRequestRecordAudio);
|
||||
returnedState = await ch.invokeMethod<String>(methodRequestRecordAudio);
|
||||
} catch (_) {
|
||||
// Channel-side failure (e.g. missing handler in a debug build).
|
||||
// Fall back to whatever state we currently hold; if still
|
||||
@@ -232,6 +231,11 @@ class AndroidPermissionsService {
|
||||
// "proceed in listen-only".
|
||||
return _state.value;
|
||||
}
|
||||
final parsedReturnedState = _parseState(returnedState);
|
||||
if (parsedReturnedState != AndroidRecordAudioPermissionState.unknown) {
|
||||
_state.value = parsedReturnedState;
|
||||
return parsedReturnedState;
|
||||
}
|
||||
// M1 fix (corrected): only short-circuit if the platform changed
|
||||
// the state synchronously to a resolved value. A still-unknown
|
||||
// state means we must wait. A still-equal-to-pre-invoke state
|
||||
|
||||
Reference in New Issue
Block a user