package com.google.firebase.crashlytics.internal.common; import android.content.Context; import android.content.SharedPreferences; import android.os.Build; import com.google.firebase.crashlytics.internal.Logger; import com.google.firebase.iid.internal.FirebaseInstanceIdInternal; import java.util.Locale; import java.util.UUID; import java.util.regex.Pattern; /* loaded from: classes.dex */ public class IdManager implements InstallIdProvider { public static final String DEFAULT_VERSION_NAME = "0.0"; static final String PREFKEY_ADVERTISING_ID = "crashlytics.advertising.id"; static final String PREFKEY_FIREBASE_IID = "firebase.installation.id"; static final String PREFKEY_INSTALLATION_UUID = "crashlytics.installation.id"; static final String PREFKEY_LEGACY_INSTALLATION_UUID = "crashlytics.installation.id"; private final Context appContext; private final String appIdentifier; private String crashlyticsInstallId; private final FirebaseInstanceIdInternal firebaseInstallId; private final InstallerPackageNameProvider installerPackageNameProvider; private static final Pattern ID_PATTERN = Pattern.compile("[^\\p{Alnum}]"); private static final String FORWARD_SLASH_REGEX = Pattern.quote("/"); public IdManager(Context context, String str, FirebaseInstanceIdInternal firebaseInstanceIdInternal) { if (context == null) { throw new IllegalArgumentException("appContext must not be null"); } if (str == null) { throw new IllegalArgumentException("appIdentifier must not be null"); } this.appContext = context; this.appIdentifier = str; this.firebaseInstallId = firebaseInstanceIdInternal; this.installerPackageNameProvider = new InstallerPackageNameProvider(); } private static String formatId(String str) { if (str == null) { return null; } return ID_PATTERN.matcher(str).replaceAll("").toLowerCase(Locale.US); } @Override // com.google.firebase.crashlytics.internal.common.InstallIdProvider public String getCrashlyticsInstallId() { synchronized (this) { String str = this.crashlyticsInstallId; if (str != null) { return str; } SharedPreferences sharedPrefs = CommonUtils.getSharedPrefs(this.appContext); String id = this.firebaseInstallId.getId(); String string = sharedPrefs.getString(PREFKEY_FIREBASE_IID, null); if (string == null) { SharedPreferences legacySharedPrefs = CommonUtils.getLegacySharedPrefs(this.appContext); String string2 = legacySharedPrefs.getString("crashlytics.installation.id", null); Logger logger = Logger.getLogger(); StringBuilder sb = new StringBuilder("No cached FID; legacy id is "); sb.append(string2); logger.d(sb.toString()); if (string2 == null) { this.crashlyticsInstallId = createAndStoreIid(id, sharedPrefs); } else { this.crashlyticsInstallId = string2; migrateLegacyId(string2, id, sharedPrefs, legacySharedPrefs); } return this.crashlyticsInstallId; } if (string.equals(id)) { this.crashlyticsInstallId = sharedPrefs.getString("crashlytics.installation.id", null); Logger logger2 = Logger.getLogger(); StringBuilder sb2 = new StringBuilder("Found matching FID, using Crashlytics IID: "); sb2.append(this.crashlyticsInstallId); logger2.d(sb2.toString()); if (this.crashlyticsInstallId == null) { this.crashlyticsInstallId = createAndStoreIid(id, sharedPrefs); } } else { this.crashlyticsInstallId = createAndStoreIid(id, sharedPrefs); } return this.crashlyticsInstallId; } } private void migrateLegacyId(String str, String str2, SharedPreferences sharedPreferences, SharedPreferences sharedPreferences2) { synchronized (this) { Logger logger = Logger.getLogger(); StringBuilder sb = new StringBuilder("Migrating legacy Crashlytics IID: "); sb.append(str); logger.d(sb.toString()); sharedPreferences.edit().putString("crashlytics.installation.id", str).putString(PREFKEY_FIREBASE_IID, str2).apply(); sharedPreferences2.edit().remove("crashlytics.installation.id").remove(PREFKEY_ADVERTISING_ID).apply(); } } private String createAndStoreIid(String str, SharedPreferences sharedPreferences) { String formatId; synchronized (this) { formatId = formatId(UUID.randomUUID().toString()); Logger logger = Logger.getLogger(); StringBuilder sb = new StringBuilder("Created new Crashlytics IID: "); sb.append(formatId); logger.d(sb.toString()); sharedPreferences.edit().putString("crashlytics.installation.id", formatId).putString(PREFKEY_FIREBASE_IID, str).apply(); } return formatId; } public String getOsDisplayVersionString() { return removeForwardSlashesIn(Build.VERSION.RELEASE); } public String getOsBuildVersionString() { return removeForwardSlashesIn(Build.VERSION.INCREMENTAL); } public String getModelName() { return String.format(Locale.US, "%s/%s", removeForwardSlashesIn(Build.MANUFACTURER), removeForwardSlashesIn(Build.MODEL)); } private String removeForwardSlashesIn(String str) { return str.replaceAll(FORWARD_SLASH_REGEX, ""); } public String getInstallerPackageName() { return this.installerPackageNameProvider.getInstallerPackageName(this.appContext); } public String getAppIdentifier() { return this.appIdentifier; } }