Skip to content

Regex is not filtering on HMS (HarmonyOS) #243

@hsynksahin

Description

@hsynksahin

On my already deployed app, I've got an error feedback which is that my app can not read the message. I've checked every log and observed the situation on user's phone.

The problem is intead of the actual code in the message the OS sends back the B002 part of the message as the code. Furthermore my regex checks not accepting this code and user can not use this function. (This function is mandatory in this app so user can not use the app itself !)

My conclusion is the OS is not recognizing the REGEX given to the SmsAutoFill. And returning the last word in the message. Here is a part of my code:

Future<bool> _sendVerificationMessage() async {
  await _smsListener.listenForCode(smsCodeRegexPattern: r'\d{6}');

  // Sends message
_verificationCode = await _smsListener.getAppSignature.then((signature) async => await messageService.sendPhoneVerification(
              localization: Localization.of(context),
              phoneNumber: _state!.model.phoneNumber.replaceAll(' ', '').replaceAll('+', ''),
              signature: signature,
            ));
  
  _codeListener?.cancel();
  _codeListener = null;
  _codeListener = _smsListener.code.listen(_listenCode);
}

void _listenCode(String code) {
  if (!mounted) return;
  
  Log.trace('[PhoneScreen] Listened for code:\n`$code`');
  
  var filteredCode = RegExp(r'\d{6}').stringMatch(code);
  if (filteredCode == null) {
    Log.error(
      '[PhoneScreen] Listened code incompatible',
      stackTrace: StackTrace.current,
      upload: true,
    );
    return;
  }

  _checkCode(filteredCode); // Pastes code and proceeds...
}

There is no problems on any other Android device. I got this error only on one user's device which has OS as Huawei HMS. Downloaded app via GBox trough Google Play (This might be the one causing problem too).

Anyone else got this problem? Or as temporary solution, Is there a way to get the whole the message then parse the code myself ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions