Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.facebook;
- import android.annotation.SuppressLint;
- import android.content.Intent;
- import android.os.Bundle;
- import android.os.Parcel;
- import android.os.Parcelable;
- import android.os.Parcelable.Creator;
- import android.text.TextUtils;
- import androidx.annotation.Nullable;
- import com.facebook.internal.Utility;
- import com.facebook.internal.Utility.GraphMeRequestWithCacheCallback;
- import com.facebook.internal.Validate;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.Date;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- public final class AccessToken implements Parcelable {
- public static final String ACCESS_TOKEN_KEY = "access_token";
- private static final String APPLICATION_ID_KEY = "application_id";
- public static final Creator<AccessToken> CREATOR = new Creator() {
- public AccessToken createFromParcel(Parcel parcel) {
- return new AccessToken(parcel);
- }
- public AccessToken[] newArray(int i) {
- return new AccessToken[i];
- }
- };
- private static final int CURRENT_JSON_FORMAT = 1;
- public static final String DATA_ACCESS_EXPIRATION_TIME = "data_access_expiration_time";
- private static final String DECLINED_PERMISSIONS_KEY = "declined_permissions";
- private static final AccessTokenSource DEFAULT_ACCESS_TOKEN_SOURCE = AccessTokenSource.FACEBOOK_APPLICATION_WEB;
- private static final Date DEFAULT_EXPIRATION_TIME = MAX_DATE;
- private static final Date DEFAULT_LAST_REFRESH_TIME = new Date();
- private static final String EXPIRED_PERMISSIONS_KEY = "expired_permissions";
- private static final String EXPIRES_AT_KEY = "expires_at";
- public static final String EXPIRES_IN_KEY = "expires_in";
- private static final String LAST_REFRESH_KEY = "last_refresh";
- private static final Date MAX_DATE = new Date(Long.MAX_VALUE);
- private static final String PERMISSIONS_KEY = "permissions";
- private static final String SOURCE_KEY = "source";
- private static final String TOKEN_KEY = "token";
- public static final String USER_ID_KEY = "user_id";
- private static final String VERSION_KEY = "version";
- private final String applicationId;
- private final Date dataAccessExpirationTime;
- private final Set<String> declinedPermissions;
- private final Set<String> expiredPermissions;
- private final Date expires;
- private final Date lastRefresh;
- /* renamed from: permissions reason: collision with root package name */
- private final Set<String> f11permissions;
- private final AccessTokenSource source;
- private final String token;
- private final String userId;
- public interface AccessTokenCreationCallback {
- void onError(FacebookException facebookException);
- void onSuccess(AccessToken accessToken);
- }
- public interface AccessTokenRefreshCallback {
- void OnTokenRefreshFailed(FacebookException facebookException);
- void OnTokenRefreshed(AccessToken accessToken);
- }
- public int describeContents() {
- return 0;
- }
- public AccessToken(String str, String str2, String str3, @Nullable Collection<String> collection, @Nullable Collection<String> collection2, @Nullable Collection<String> collection3, @Nullable AccessTokenSource accessTokenSource, @Nullable Date date, @Nullable Date date2, @Nullable Date date3) {
- Validate.notNullOrEmpty(str, "accessToken");
- Validate.notNullOrEmpty(str2, "applicationId");
- Validate.notNullOrEmpty(str3, "userId");
- if (date == null) {
- date = DEFAULT_EXPIRATION_TIME;
- }
- this.expires = date;
- this.f11permissions = Collections.unmodifiableSet(collection != null ? new HashSet(collection) : new HashSet());
- this.declinedPermissions = Collections.unmodifiableSet(collection2 != null ? new HashSet(collection2) : new HashSet());
- this.expiredPermissions = Collections.unmodifiableSet(collection3 != null ? new HashSet(collection3) : new HashSet());
- this.token = str;
- if (accessTokenSource == null) {
- accessTokenSource = DEFAULT_ACCESS_TOKEN_SOURCE;
- }
- this.source = accessTokenSource;
- if (date2 == null) {
- date2 = DEFAULT_LAST_REFRESH_TIME;
- }
- this.lastRefresh = date2;
- this.applicationId = str2;
- this.userId = str3;
- if (date3 == null || date3.getTime() == 0) {
- date3 = DEFAULT_EXPIRATION_TIME;
- }
- this.dataAccessExpirationTime = date3;
- }
- public static AccessToken getCurrentAccessToken() {
- return AccessTokenManager.getInstance().getCurrentAccessToken();
- }
- public static boolean isCurrentAccessTokenActive() {
- AccessToken currentAccessToken = AccessTokenManager.getInstance().getCurrentAccessToken();
- return currentAccessToken != null && !currentAccessToken.isExpired();
- }
- public static boolean isDataAccessActive() {
- AccessToken currentAccessToken = AccessTokenManager.getInstance().getCurrentAccessToken();
- return currentAccessToken != null && !currentAccessToken.isDataAccessExpired();
- }
- static void expireCurrentAccessToken() {
- AccessToken currentAccessToken = AccessTokenManager.getInstance().getCurrentAccessToken();
- if (currentAccessToken != null) {
- setCurrentAccessToken(createExpired(currentAccessToken));
- }
- }
- public static void setCurrentAccessToken(AccessToken accessToken) {
- AccessTokenManager.getInstance().setCurrentAccessToken(accessToken);
- }
- public static void refreshCurrentAccessTokenAsync() {
- AccessTokenManager.getInstance().refreshCurrentAccessToken(null);
- }
- public static void refreshCurrentAccessTokenAsync(AccessTokenRefreshCallback accessTokenRefreshCallback) {
- AccessTokenManager.getInstance().refreshCurrentAccessToken(accessTokenRefreshCallback);
- }
- public String getToken() {
- return this.token;
- }
- public Date getExpires() {
- return this.expires;
- }
- public Date getDataAccessExpirationTime() {
- return this.dataAccessExpirationTime;
- }
- public Set<String> getPermissions() {
- return this.f11permissions;
- }
- public Set<String> getDeclinedPermissions() {
- return this.declinedPermissions;
- }
- public Set<String> getExpiredPermissions() {
- return this.expiredPermissions;
- }
- public AccessTokenSource getSource() {
- return this.source;
- }
- public Date getLastRefresh() {
- return this.lastRefresh;
- }
- public String getApplicationId() {
- return this.applicationId;
- }
- public String getUserId() {
- return this.userId;
- }
- public static void createFromNativeLinkingIntent(Intent intent, final String str, final AccessTokenCreationCallback accessTokenCreationCallback) {
- Validate.notNull(intent, "intent");
- if (intent.getExtras() == null) {
- accessTokenCreationCallback.onError(new FacebookException("No extras found on intent"));
- return;
- }
- final Bundle bundle = new Bundle(intent.getExtras());
- String string = bundle.getString("access_token");
- if (string == null || string.isEmpty()) {
- accessTokenCreationCallback.onError(new FacebookException("No access token found on intent"));
- return;
- }
- String string2 = bundle.getString("user_id");
- if (string2 == null || string2.isEmpty()) {
- Utility.getGraphMeRequestWithCacheAsync(string, new GraphMeRequestWithCacheCallback() {
- public void onSuccess(JSONObject jSONObject) {
- try {
- bundle.putString("user_id", jSONObject.getString("id"));
- accessTokenCreationCallback.onSuccess(AccessToken.createFromBundle(null, bundle, AccessTokenSource.FACEBOOK_APPLICATION_WEB, new Date(), str));
- } catch (JSONException unused) {
- accessTokenCreationCallback.onError(new FacebookException("Unable to generate access token due to missing user id"));
- }
- }
- public void onFailure(FacebookException facebookException) {
- accessTokenCreationCallback.onError(facebookException);
- }
- });
- } else {
- accessTokenCreationCallback.onSuccess(createFromBundle(null, bundle, AccessTokenSource.FACEBOOK_APPLICATION_WEB, new Date(), str));
- }
- }
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("{AccessToken");
- sb.append(" token:");
- sb.append(tokenToString());
- appendPermissions(sb);
- sb.append("}");
- return sb.toString();
- }
- public boolean equals(Object obj) {
- boolean z = true;
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof AccessToken)) {
- return false;
- }
- AccessToken accessToken = (AccessToken) obj;
- if (!this.expires.equals(accessToken.expires) || !this.f11permissions.equals(accessToken.f11permissions) || !this.declinedPermissions.equals(accessToken.declinedPermissions) || !this.expiredPermissions.equals(accessToken.expiredPermissions) || !this.token.equals(accessToken.token) || this.source != accessToken.source || !this.lastRefresh.equals(accessToken.lastRefresh) || (this.applicationId != null ? !this.applicationId.equals(accessToken.applicationId) : accessToken.applicationId != null) || !this.userId.equals(accessToken.userId) || !this.dataAccessExpirationTime.equals(accessToken.dataAccessExpirationTime)) {
- z = false;
- }
- return z;
- }
- public int hashCode() {
- return ((((((((((((((((((527 + this.expires.hashCode()) * 31) + this.f11permissions.hashCode()) * 31) + this.declinedPermissions.hashCode()) * 31) + this.expiredPermissions.hashCode()) * 31) + this.token.hashCode()) * 31) + this.source.hashCode()) * 31) + this.lastRefresh.hashCode()) * 31) + (this.applicationId == null ? 0 : this.applicationId.hashCode())) * 31) + this.userId.hashCode()) * 31) + this.dataAccessExpirationTime.hashCode();
- }
- @SuppressLint({"FieldGetter"})
- static AccessToken createFromRefresh(AccessToken accessToken, Bundle bundle) {
- AccessToken accessToken2 = accessToken;
- Bundle bundle2 = bundle;
- if (accessToken2.source == AccessTokenSource.FACEBOOK_APPLICATION_WEB || accessToken2.source == AccessTokenSource.FACEBOOK_APPLICATION_NATIVE || accessToken2.source == AccessTokenSource.FACEBOOK_APPLICATION_SERVICE) {
- Date bundleLongAsDate = Utility.getBundleLongAsDate(bundle2, EXPIRES_IN_KEY, new Date(0));
- String string = bundle2.getString("access_token");
- Date bundleLongAsDate2 = Utility.getBundleLongAsDate(bundle2, DATA_ACCESS_EXPIRATION_TIME, new Date(0));
- if (Utility.isNullOrEmpty(string)) {
- return null;
- }
- AccessToken accessToken3 = new AccessToken(string, accessToken2.applicationId, accessToken.getUserId(), accessToken.getPermissions(), accessToken.getDeclinedPermissions(), accessToken.getExpiredPermissions(), accessToken2.source, bundleLongAsDate, new Date(), bundleLongAsDate2);
- return accessToken3;
- }
- StringBuilder sb = new StringBuilder();
- sb.append("Invalid token source: ");
- sb.append(accessToken2.source);
- throw new FacebookException(sb.toString());
- }
- static AccessToken createExpired(AccessToken accessToken) {
- AccessToken accessToken2 = new AccessToken(accessToken.token, accessToken.applicationId, accessToken.getUserId(), accessToken.getPermissions(), accessToken.getDeclinedPermissions(), accessToken.getExpiredPermissions(), accessToken.source, new Date(), new Date(), accessToken.dataAccessExpirationTime);
- return accessToken2;
- }
- static AccessToken createFromLegacyCache(Bundle bundle) {
- List permissionsFromBundle = getPermissionsFromBundle(bundle, LegacyTokenHelper.PERMISSIONS_KEY);
- List permissionsFromBundle2 = getPermissionsFromBundle(bundle, LegacyTokenHelper.DECLINED_PERMISSIONS_KEY);
- List permissionsFromBundle3 = getPermissionsFromBundle(bundle, LegacyTokenHelper.EXPIRED_PERMISSIONS_KEY);
- String applicationId2 = LegacyTokenHelper.getApplicationId(bundle);
- if (Utility.isNullOrEmpty(applicationId2)) {
- applicationId2 = FacebookSdk.getApplicationId();
- }
- String str = applicationId2;
- String token2 = LegacyTokenHelper.getToken(bundle);
- try {
- AccessToken accessToken = new AccessToken(token2, str, Utility.awaitGetGraphMeRequestWithCache(token2).getString("id"), permissionsFromBundle, permissionsFromBundle2, permissionsFromBundle3, LegacyTokenHelper.getSource(bundle), LegacyTokenHelper.getDate(bundle, LegacyTokenHelper.EXPIRATION_DATE_KEY), LegacyTokenHelper.getDate(bundle, LegacyTokenHelper.LAST_REFRESH_DATE_KEY), null);
- return accessToken;
- } catch (JSONException unused) {
- return null;
- }
- }
- static List<String> getPermissionsFromBundle(Bundle bundle, String str) {
- ArrayList stringArrayList = bundle.getStringArrayList(str);
- if (stringArrayList == null) {
- return Collections.emptyList();
- }
- return Collections.unmodifiableList(new ArrayList(stringArrayList));
- }
- public boolean isExpired() {
- return new Date().after(this.expires);
- }
- public boolean isDataAccessExpired() {
- return new Date().after(this.dataAccessExpirationTime);
- }
- /* access modifiers changed from: 0000 */
- public JSONObject toJSONObject() throws JSONException {
- JSONObject jSONObject = new JSONObject();
- jSONObject.put("version", 1);
- jSONObject.put(TOKEN_KEY, this.token);
- jSONObject.put("expires_at", this.expires.getTime());
- jSONObject.put("permissions", new JSONArray(this.f11permissions));
- jSONObject.put(DECLINED_PERMISSIONS_KEY, new JSONArray(this.declinedPermissions));
- jSONObject.put(EXPIRED_PERMISSIONS_KEY, new JSONArray(this.expiredPermissions));
- jSONObject.put(LAST_REFRESH_KEY, this.lastRefresh.getTime());
- jSONObject.put("source", this.source.name());
- jSONObject.put(APPLICATION_ID_KEY, this.applicationId);
- jSONObject.put("user_id", this.userId);
- jSONObject.put(DATA_ACCESS_EXPIRATION_TIME, this.dataAccessExpirationTime.getTime());
- return jSONObject;
- }
- static AccessToken createFromJSONObject(JSONObject jSONObject) throws JSONException {
- Collection jsonArrayToStringList;
- if (jSONObject.getInt("version") <= 1) {
- String string = jSONObject.getString(TOKEN_KEY);
- Date date = new Date(jSONObject.getLong("expires_at"));
- JSONArray jSONArray = jSONObject.getJSONArray("permissions");
- JSONArray jSONArray2 = jSONObject.getJSONArray(DECLINED_PERMISSIONS_KEY);
- JSONArray optJSONArray = jSONObject.optJSONArray(EXPIRED_PERMISSIONS_KEY);
- Date date2 = new Date(jSONObject.getLong(LAST_REFRESH_KEY));
- AccessTokenSource valueOf = AccessTokenSource.valueOf(jSONObject.getString("source"));
- String string2 = jSONObject.getString(APPLICATION_ID_KEY);
- String string3 = jSONObject.getString("user_id");
- Date date3 = new Date(jSONObject.optLong(DATA_ACCESS_EXPIRATION_TIME, 0));
- List jsonArrayToStringList2 = Utility.jsonArrayToStringList(jSONArray);
- List jsonArrayToStringList3 = Utility.jsonArrayToStringList(jSONArray2);
- if (optJSONArray == null) {
- jsonArrayToStringList = new ArrayList();
- } else {
- jsonArrayToStringList = Utility.jsonArrayToStringList(optJSONArray);
- }
- AccessToken accessToken = new AccessToken(string, string2, string3, jsonArrayToStringList2, jsonArrayToStringList3, jsonArrayToStringList, valueOf, date, date2, date3);
- return accessToken;
- }
- throw new FacebookException("Unknown AccessToken serialization format.");
- }
- /* access modifiers changed from: private */
- public static AccessToken createFromBundle(List<String> list, Bundle bundle, AccessTokenSource accessTokenSource, Date date, String str) {
- Bundle bundle2 = bundle;
- String string = bundle.getString("access_token");
- Date bundleLongAsDate = Utility.getBundleLongAsDate(bundle, EXPIRES_IN_KEY, date);
- String string2 = bundle.getString("user_id");
- Date bundleLongAsDate2 = Utility.getBundleLongAsDate(bundle, DATA_ACCESS_EXPIRATION_TIME, new Date(0));
- if (Utility.isNullOrEmpty(string) || bundleLongAsDate == null) {
- return null;
- }
- AccessToken accessToken = new AccessToken(string, str, string2, list, null, null, accessTokenSource, bundleLongAsDate, new Date(), bundleLongAsDate2);
- return accessToken;
- }
- private String tokenToString() {
- if (this.token == null) {
- return "null";
- }
- return FacebookSdk.isLoggingBehaviorEnabled(LoggingBehavior.INCLUDE_ACCESS_TOKENS) ? this.token : "ACCESS_TOKEN_REMOVED";
- }
- private void appendPermissions(StringBuilder sb) {
- sb.append(" permissions:");
- if (this.f11permissions == null) {
- sb.append("null");
- return;
- }
- sb.append("[");
- sb.append(TextUtils.join(", ", this.f11permissions));
- sb.append("]");
- }
- AccessToken(Parcel parcel) {
- this.expires = new Date(parcel.readLong());
- ArrayList arrayList = new ArrayList();
- parcel.readStringList(arrayList);
- this.f11permissions = Collections.unmodifiableSet(new HashSet(arrayList));
- arrayList.clear();
- parcel.readStringList(arrayList);
- this.declinedPermissions = Collections.unmodifiableSet(new HashSet(arrayList));
- arrayList.clear();
- parcel.readStringList(arrayList);
- this.expiredPermissions = Collections.unmodifiableSet(new HashSet(arrayList));
- this.token = parcel.readString();
- this.source = AccessTokenSource.valueOf(parcel.readString());
- this.lastRefresh = new Date(parcel.readLong());
- this.applicationId = parcel.readString();
- this.userId = parcel.readString();
- this.dataAccessExpirationTime = new Date(parcel.readLong());
- }
- public void writeToParcel(Parcel parcel, int i) {
- parcel.writeLong(this.expires.getTime());
- parcel.writeStringList(new ArrayList(this.f11permissions));
- parcel.writeStringList(new ArrayList(this.declinedPermissions));
- parcel.writeStringList(new ArrayList(this.expiredPermissions));
- parcel.writeString(this.token);
- parcel.writeString(this.source.name());
- parcel.writeLong(this.lastRefresh.getTime());
- parcel.writeString(this.applicationId);
- parcel.writeString(this.userId);
- parcel.writeLong(this.dataAccessExpirationTime.getTime());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement