class LoggingUtils {

    static void addNameAndVersion(
            @NonNull Map<String, Object> paramsObject,
            @NonNull Context context) {
        Context applicationContext = context.getApplicationContext();
        if (applicationContext != null && applicationContext.getPackageManager() != null) {
            try {
                PackageInfo info = applicationContext.getPackageManager().getPackageInfo(
                        applicationContext.getPackageName(), 0);

                String nameString = null;
                if (info.applicationInfo != null) {
                    CharSequence name =
                            info.applicationInfo.loadLabel(applicationContext.getPackageManager());
                    if (name != null) {
                        nameString = name.toString();
                    }
                    paramsObject.put(FIELD_APP_NAME, nameString);
                }

                if (StripeTextUtils.isBlank(nameString)) {
                    paramsObject.put(FIELD_APP_NAME, info.packageName);
                }

                paramsObject.put(FIELD_APP_VERSION, info.versionCode);
            } catch (PackageManager.NameNotFoundException nameNotFound) {
                paramsObject.put(FIELD_APP_NAME, UNKNOWN);
                paramsObject.put(FIELD_APP_VERSION, UNKNOWN);
            }
        } else {
            paramsObject.put(FIELD_APP_NAME, NO_CONTEXT);
            paramsObject.put(FIELD_APP_VERSION, NO_CONTEXT);
        }
    }

}