gatherInformation method

Future<void> gatherInformation()

Implementation

Future<void> gatherInformation() async {
  final deviceInfoFuture = Future.sync(_deviceInfoService.gatherDeviceInfo);
  final localeCountryFuture = Future.sync(LocaleCountryUtil.getLocaleCountry);
  final appInfoFuture = Future.sync(_appInfoService.gatherAppInfo);

  // GEO INFO — fire-and-forget, does not block event sending
  unawaited(_fetchGeoInfoAsync());

  // DEVICE INFO
  Map<String, Object?>? deviceInfo;
  try {
    deviceInfo = await deviceInfoFuture;
  } catch (e, st) {
    dbLogger.severe('Error gathering device info', e, st);
  }
  if (deviceInfo != null) {
    await Prefs.setString(devicePropertiesKey, jsonEncode(deviceInfo));
  }

  // LOCALE COUNTRY (SIM > Network > Locale)
  try {
    final localeCountry = await localeCountryFuture;
    if (localeCountry.isNotEmpty) {
      await _lock.synchronized(() {
        _geoInfoProperties['country'] = localeCountry;
      });
    }
  } catch (e, st) {
    dbLogger.severe('Error gathering locale country', e, st);
  }

  // APP INFO + set appid/platform common properties
  Map<String, Object?>? appInfo;
  try {
    appInfo = await appInfoFuture;
  } catch (e, st) {
    dbLogger.severe('Error gathering app info', e, st);
  }
  if (appInfo != null) {
    await Prefs.setString(appPropertiesKey, jsonEncode(appInfo));

    // Set appid and platform as common properties (lowercase)
    final appId = appInfo['app_id'];
    final platform = appInfo['app_platform'];
    if (appId != null) {
      await CommonPropertiesUtil.setInternalProperty('appid', appId);
    }
    if (platform != null) {
      await CommonPropertiesUtil.setInternalProperty('platform', platform);
    }
  }
}