package com.amazonaws.auth; import com.amazonaws.AmazonWebServiceRequest; import com.amazonaws.services.cognitoidentity.AmazonCognitoIdentity; import com.amazonaws.services.cognitoidentity.model.GetIdRequest; import com.amazonaws.services.cognitoidentity.model.GetIdResult; import com.amazonaws.services.cognitoidentity.model.GetOpenIdTokenRequest; import com.amazonaws.services.cognitoidentity.model.GetOpenIdTokenResult; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /* loaded from: classes.dex */ public abstract class AWSAbstractCognitoIdentityProvider implements AWSCognitoIdentityProvider { public final String accountId; public final AmazonCognitoIdentity cib; public String identityId; public final String identityPoolId; public String token; public Map loginsMap = new HashMap(); public List listeners = new ArrayList(); public String getAccountId() { return this.accountId; } @Override // com.amazonaws.auth.AWSCognitoIdentityProvider public String getIdentityPoolId() { return this.identityPoolId; } @Override // com.amazonaws.auth.AWSCognitoIdentityProvider public Map getLogins() { return this.loginsMap; } public String getUserAgent() { return ""; } public void setToken(String str) { this.token = str; } public AWSAbstractCognitoIdentityProvider(String str, String str2, AmazonCognitoIdentity amazonCognitoIdentity) { this.accountId = str; this.identityPoolId = str2; this.cib = amazonCognitoIdentity; } @Override // com.amazonaws.auth.AWSCognitoIdentityProvider public String getIdentityId() { if (this.identityId == null) { GetIdRequest withLogins = new GetIdRequest().withAccountId(getAccountId()).withIdentityPoolId(getIdentityPoolId()).withLogins(this.loginsMap); appendUserAgent(withLogins, getUserAgent()); GetIdResult id = this.cib.getId(withLogins); if (id.getIdentityId() != null) { identityChanged(id.getIdentityId()); } } return this.identityId; } public String getToken() { if (this.token == null) { GetOpenIdTokenRequest withLogins = new GetOpenIdTokenRequest().withIdentityId(getIdentityId()).withLogins(this.loginsMap); appendUserAgent(withLogins, getUserAgent()); GetOpenIdTokenResult openIdToken = this.cib.getOpenIdToken(withLogins); if (!openIdToken.getIdentityId().equals(getIdentityId())) { identityChanged(openIdToken.getIdentityId()); } this.token = openIdToken.getToken(); } return this.token; } @Override // com.amazonaws.auth.AWSCognitoIdentityProvider public boolean isAuthenticated() { Map map = this.loginsMap; return map != null && map.size() > 0; } @Override // com.amazonaws.auth.AWSCognitoIdentityProvider public void registerIdentityChangedListener(IdentityChangedListener identityChangedListener) { this.listeners.add(identityChangedListener); } @Override // com.amazonaws.auth.AWSCognitoIdentityProvider public void identityChanged(String str) { String str2 = this.identityId; if (str2 == null || !str2.equals(str)) { String str3 = this.identityId; this.identityId = str; Iterator it = this.listeners.iterator(); while (it.hasNext()) { ((IdentityChangedListener) it.next()).identityChanged(str3, this.identityId); } } } public void appendUserAgent(AmazonWebServiceRequest amazonWebServiceRequest, String str) { amazonWebServiceRequest.getRequestClientOptions().appendUserAgent(str); } public void update(String str, String str2) { String str3 = this.identityId; if (str3 == null || !str3.equals(str)) { identityChanged(str); } String str4 = this.token; if (str4 == null || !str4.equals(str2)) { this.token = str2; } } @Override // com.amazonaws.auth.AWSIdentityProvider public String refresh() { getIdentityId(); String token = getToken(); update(getIdentityId(), token); return token; } }