XaskeL

Untitled

Oct 17th, 2019
130
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.facebook;
  2.  
  3. import android.annotation.SuppressLint;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.os.Parcel;
  7. import android.os.Parcelable;
  8. import android.os.Parcelable.Creator;
  9. import android.text.TextUtils;
  10. import androidx.annotation.Nullable;
  11. import com.facebook.internal.Utility;
  12. import com.facebook.internal.Utility.GraphMeRequestWithCacheCallback;
  13. import com.facebook.internal.Validate;
  14. import java.util.ArrayList;
  15. import java.util.Collection;
  16. import java.util.Collections;
  17. import java.util.Date;
  18. import java.util.HashSet;
  19. import java.util.List;
  20. import java.util.Set;
  21. import org.json.JSONArray;
  22. import org.json.JSONException;
  23. import org.json.JSONObject;
  24.  
  25. public final class AccessToken implements Parcelable {
  26. public static final String ACCESS_TOKEN_KEY = "access_token";
  27. private static final String APPLICATION_ID_KEY = "application_id";
  28. public static final Creator<AccessToken> CREATOR = new Creator() {
  29. public AccessToken createFromParcel(Parcel parcel) {
  30. return new AccessToken(parcel);
  31. }
  32.  
  33. public AccessToken[] newArray(int i) {
  34. return new AccessToken[i];
  35. }
  36. };
  37. private static final int CURRENT_JSON_FORMAT = 1;
  38. public static final String DATA_ACCESS_EXPIRATION_TIME = "data_access_expiration_time";
  39. private static final String DECLINED_PERMISSIONS_KEY = "declined_permissions";
  40. private static final AccessTokenSource DEFAULT_ACCESS_TOKEN_SOURCE = AccessTokenSource.FACEBOOK_APPLICATION_WEB;
  41. private static final Date DEFAULT_EXPIRATION_TIME = MAX_DATE;
  42. private static final Date DEFAULT_LAST_REFRESH_TIME = new Date();
  43. private static final String EXPIRED_PERMISSIONS_KEY = "expired_permissions";
  44. private static final String EXPIRES_AT_KEY = "expires_at";
  45. public static final String EXPIRES_IN_KEY = "expires_in";
  46. private static final String LAST_REFRESH_KEY = "last_refresh";
  47. private static final Date MAX_DATE = new Date(Long.MAX_VALUE);
  48. private static final String PERMISSIONS_KEY = "permissions";
  49. private static final String SOURCE_KEY = "source";
  50. private static final String TOKEN_KEY = "token";
  51. public static final String USER_ID_KEY = "user_id";
  52. private static final String VERSION_KEY = "version";
  53. private final String applicationId;
  54. private final Date dataAccessExpirationTime;
  55. private final Set<String> declinedPermissions;
  56. private final Set<String> expiredPermissions;
  57. private final Date expires;
  58. private final Date lastRefresh;
  59.  
  60. /* renamed from: permissions reason: collision with root package name */
  61. private final Set<String> f11permissions;
  62. private final AccessTokenSource source;
  63. private final String token;
  64. private final String userId;
  65.  
  66. public interface AccessTokenCreationCallback {
  67. void onError(FacebookException facebookException);
  68.  
  69. void onSuccess(AccessToken accessToken);
  70. }
  71.  
  72. public interface AccessTokenRefreshCallback {
  73. void OnTokenRefreshFailed(FacebookException facebookException);
  74.  
  75. void OnTokenRefreshed(AccessToken accessToken);
  76. }
  77.  
  78. public int describeContents() {
  79. return 0;
  80. }
  81.  
  82. 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) {
  83. Validate.notNullOrEmpty(str, "accessToken");
  84. Validate.notNullOrEmpty(str2, "applicationId");
  85. Validate.notNullOrEmpty(str3, "userId");
  86. if (date == null) {
  87. date = DEFAULT_EXPIRATION_TIME;
  88. }
  89. this.expires = date;
  90. this.f11permissions = Collections.unmodifiableSet(collection != null ? new HashSet(collection) : new HashSet());
  91. this.declinedPermissions = Collections.unmodifiableSet(collection2 != null ? new HashSet(collection2) : new HashSet());
  92. this.expiredPermissions = Collections.unmodifiableSet(collection3 != null ? new HashSet(collection3) : new HashSet());
  93. this.token = str;
  94. if (accessTokenSource == null) {
  95. accessTokenSource = DEFAULT_ACCESS_TOKEN_SOURCE;
  96. }
  97. this.source = accessTokenSource;
  98. if (date2 == null) {
  99. date2 = DEFAULT_LAST_REFRESH_TIME;
  100. }
  101. this.lastRefresh = date2;
  102. this.applicationId = str2;
  103. this.userId = str3;
  104. if (date3 == null || date3.getTime() == 0) {
  105. date3 = DEFAULT_EXPIRATION_TIME;
  106. }
  107. this.dataAccessExpirationTime = date3;
  108. }
  109.  
  110. public static AccessToken getCurrentAccessToken() {
  111. return AccessTokenManager.getInstance().getCurrentAccessToken();
  112. }
  113.  
  114. public static boolean isCurrentAccessTokenActive() {
  115. AccessToken currentAccessToken = AccessTokenManager.getInstance().getCurrentAccessToken();
  116. return currentAccessToken != null && !currentAccessToken.isExpired();
  117. }
  118.  
  119. public static boolean isDataAccessActive() {
  120. AccessToken currentAccessToken = AccessTokenManager.getInstance().getCurrentAccessToken();
  121. return currentAccessToken != null && !currentAccessToken.isDataAccessExpired();
  122. }
  123.  
  124. static void expireCurrentAccessToken() {
  125. AccessToken currentAccessToken = AccessTokenManager.getInstance().getCurrentAccessToken();
  126. if (currentAccessToken != null) {
  127. setCurrentAccessToken(createExpired(currentAccessToken));
  128. }
  129. }
  130.  
  131. public static void setCurrentAccessToken(AccessToken accessToken) {
  132. AccessTokenManager.getInstance().setCurrentAccessToken(accessToken);
  133. }
  134.  
  135. public static void refreshCurrentAccessTokenAsync() {
  136. AccessTokenManager.getInstance().refreshCurrentAccessToken(null);
  137. }
  138.  
  139. public static void refreshCurrentAccessTokenAsync(AccessTokenRefreshCallback accessTokenRefreshCallback) {
  140. AccessTokenManager.getInstance().refreshCurrentAccessToken(accessTokenRefreshCallback);
  141. }
  142.  
  143. public String getToken() {
  144. return this.token;
  145. }
  146.  
  147. public Date getExpires() {
  148. return this.expires;
  149. }
  150.  
  151. public Date getDataAccessExpirationTime() {
  152. return this.dataAccessExpirationTime;
  153. }
  154.  
  155. public Set<String> getPermissions() {
  156. return this.f11permissions;
  157. }
  158.  
  159. public Set<String> getDeclinedPermissions() {
  160. return this.declinedPermissions;
  161. }
  162.  
  163. public Set<String> getExpiredPermissions() {
  164. return this.expiredPermissions;
  165. }
  166.  
  167. public AccessTokenSource getSource() {
  168. return this.source;
  169. }
  170.  
  171. public Date getLastRefresh() {
  172. return this.lastRefresh;
  173. }
  174.  
  175. public String getApplicationId() {
  176. return this.applicationId;
  177. }
  178.  
  179. public String getUserId() {
  180. return this.userId;
  181. }
  182.  
  183. public static void createFromNativeLinkingIntent(Intent intent, final String str, final AccessTokenCreationCallback accessTokenCreationCallback) {
  184. Validate.notNull(intent, "intent");
  185. if (intent.getExtras() == null) {
  186. accessTokenCreationCallback.onError(new FacebookException("No extras found on intent"));
  187. return;
  188. }
  189. final Bundle bundle = new Bundle(intent.getExtras());
  190. String string = bundle.getString("access_token");
  191. if (string == null || string.isEmpty()) {
  192. accessTokenCreationCallback.onError(new FacebookException("No access token found on intent"));
  193. return;
  194. }
  195. String string2 = bundle.getString("user_id");
  196. if (string2 == null || string2.isEmpty()) {
  197. Utility.getGraphMeRequestWithCacheAsync(string, new GraphMeRequestWithCacheCallback() {
  198. public void onSuccess(JSONObject jSONObject) {
  199. try {
  200. bundle.putString("user_id", jSONObject.getString("id"));
  201. accessTokenCreationCallback.onSuccess(AccessToken.createFromBundle(null, bundle, AccessTokenSource.FACEBOOK_APPLICATION_WEB, new Date(), str));
  202. } catch (JSONException unused) {
  203. accessTokenCreationCallback.onError(new FacebookException("Unable to generate access token due to missing user id"));
  204. }
  205. }
  206.  
  207. public void onFailure(FacebookException facebookException) {
  208. accessTokenCreationCallback.onError(facebookException);
  209. }
  210. });
  211. } else {
  212. accessTokenCreationCallback.onSuccess(createFromBundle(null, bundle, AccessTokenSource.FACEBOOK_APPLICATION_WEB, new Date(), str));
  213. }
  214. }
  215.  
  216. public String toString() {
  217. StringBuilder sb = new StringBuilder();
  218. sb.append("{AccessToken");
  219. sb.append(" token:");
  220. sb.append(tokenToString());
  221. appendPermissions(sb);
  222. sb.append("}");
  223. return sb.toString();
  224. }
  225.  
  226. public boolean equals(Object obj) {
  227. boolean z = true;
  228. if (this == obj) {
  229. return true;
  230. }
  231. if (!(obj instanceof AccessToken)) {
  232. return false;
  233. }
  234. AccessToken accessToken = (AccessToken) obj;
  235. 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)) {
  236. z = false;
  237. }
  238. return z;
  239. }
  240.  
  241. public int hashCode() {
  242. 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();
  243. }
  244.  
  245. @SuppressLint({"FieldGetter"})
  246. static AccessToken createFromRefresh(AccessToken accessToken, Bundle bundle) {
  247. AccessToken accessToken2 = accessToken;
  248. Bundle bundle2 = bundle;
  249. if (accessToken2.source == AccessTokenSource.FACEBOOK_APPLICATION_WEB || accessToken2.source == AccessTokenSource.FACEBOOK_APPLICATION_NATIVE || accessToken2.source == AccessTokenSource.FACEBOOK_APPLICATION_SERVICE) {
  250. Date bundleLongAsDate = Utility.getBundleLongAsDate(bundle2, EXPIRES_IN_KEY, new Date(0));
  251. String string = bundle2.getString("access_token");
  252. Date bundleLongAsDate2 = Utility.getBundleLongAsDate(bundle2, DATA_ACCESS_EXPIRATION_TIME, new Date(0));
  253. if (Utility.isNullOrEmpty(string)) {
  254. return null;
  255. }
  256. AccessToken accessToken3 = new AccessToken(string, accessToken2.applicationId, accessToken.getUserId(), accessToken.getPermissions(), accessToken.getDeclinedPermissions(), accessToken.getExpiredPermissions(), accessToken2.source, bundleLongAsDate, new Date(), bundleLongAsDate2);
  257. return accessToken3;
  258. }
  259. StringBuilder sb = new StringBuilder();
  260. sb.append("Invalid token source: ");
  261. sb.append(accessToken2.source);
  262. throw new FacebookException(sb.toString());
  263. }
  264.  
  265. static AccessToken createExpired(AccessToken accessToken) {
  266. AccessToken accessToken2 = new AccessToken(accessToken.token, accessToken.applicationId, accessToken.getUserId(), accessToken.getPermissions(), accessToken.getDeclinedPermissions(), accessToken.getExpiredPermissions(), accessToken.source, new Date(), new Date(), accessToken.dataAccessExpirationTime);
  267. return accessToken2;
  268. }
  269.  
  270. static AccessToken createFromLegacyCache(Bundle bundle) {
  271. List permissionsFromBundle = getPermissionsFromBundle(bundle, LegacyTokenHelper.PERMISSIONS_KEY);
  272. List permissionsFromBundle2 = getPermissionsFromBundle(bundle, LegacyTokenHelper.DECLINED_PERMISSIONS_KEY);
  273. List permissionsFromBundle3 = getPermissionsFromBundle(bundle, LegacyTokenHelper.EXPIRED_PERMISSIONS_KEY);
  274. String applicationId2 = LegacyTokenHelper.getApplicationId(bundle);
  275. if (Utility.isNullOrEmpty(applicationId2)) {
  276. applicationId2 = FacebookSdk.getApplicationId();
  277. }
  278. String str = applicationId2;
  279. String token2 = LegacyTokenHelper.getToken(bundle);
  280. try {
  281. 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);
  282. return accessToken;
  283. } catch (JSONException unused) {
  284. return null;
  285. }
  286. }
  287.  
  288. static List<String> getPermissionsFromBundle(Bundle bundle, String str) {
  289. ArrayList stringArrayList = bundle.getStringArrayList(str);
  290. if (stringArrayList == null) {
  291. return Collections.emptyList();
  292. }
  293. return Collections.unmodifiableList(new ArrayList(stringArrayList));
  294. }
  295.  
  296. public boolean isExpired() {
  297. return new Date().after(this.expires);
  298. }
  299.  
  300. public boolean isDataAccessExpired() {
  301. return new Date().after(this.dataAccessExpirationTime);
  302. }
  303.  
  304. /* access modifiers changed from: 0000 */
  305. public JSONObject toJSONObject() throws JSONException {
  306. JSONObject jSONObject = new JSONObject();
  307. jSONObject.put("version", 1);
  308. jSONObject.put(TOKEN_KEY, this.token);
  309. jSONObject.put("expires_at", this.expires.getTime());
  310. jSONObject.put("permissions", new JSONArray(this.f11permissions));
  311. jSONObject.put(DECLINED_PERMISSIONS_KEY, new JSONArray(this.declinedPermissions));
  312. jSONObject.put(EXPIRED_PERMISSIONS_KEY, new JSONArray(this.expiredPermissions));
  313. jSONObject.put(LAST_REFRESH_KEY, this.lastRefresh.getTime());
  314. jSONObject.put("source", this.source.name());
  315. jSONObject.put(APPLICATION_ID_KEY, this.applicationId);
  316. jSONObject.put("user_id", this.userId);
  317. jSONObject.put(DATA_ACCESS_EXPIRATION_TIME, this.dataAccessExpirationTime.getTime());
  318. return jSONObject;
  319. }
  320.  
  321. static AccessToken createFromJSONObject(JSONObject jSONObject) throws JSONException {
  322. Collection jsonArrayToStringList;
  323. if (jSONObject.getInt("version") <= 1) {
  324. String string = jSONObject.getString(TOKEN_KEY);
  325. Date date = new Date(jSONObject.getLong("expires_at"));
  326. JSONArray jSONArray = jSONObject.getJSONArray("permissions");
  327. JSONArray jSONArray2 = jSONObject.getJSONArray(DECLINED_PERMISSIONS_KEY);
  328. JSONArray optJSONArray = jSONObject.optJSONArray(EXPIRED_PERMISSIONS_KEY);
  329. Date date2 = new Date(jSONObject.getLong(LAST_REFRESH_KEY));
  330. AccessTokenSource valueOf = AccessTokenSource.valueOf(jSONObject.getString("source"));
  331. String string2 = jSONObject.getString(APPLICATION_ID_KEY);
  332. String string3 = jSONObject.getString("user_id");
  333. Date date3 = new Date(jSONObject.optLong(DATA_ACCESS_EXPIRATION_TIME, 0));
  334. List jsonArrayToStringList2 = Utility.jsonArrayToStringList(jSONArray);
  335. List jsonArrayToStringList3 = Utility.jsonArrayToStringList(jSONArray2);
  336. if (optJSONArray == null) {
  337. jsonArrayToStringList = new ArrayList();
  338. } else {
  339. jsonArrayToStringList = Utility.jsonArrayToStringList(optJSONArray);
  340. }
  341. AccessToken accessToken = new AccessToken(string, string2, string3, jsonArrayToStringList2, jsonArrayToStringList3, jsonArrayToStringList, valueOf, date, date2, date3);
  342. return accessToken;
  343. }
  344. throw new FacebookException("Unknown AccessToken serialization format.");
  345. }
  346.  
  347. /* access modifiers changed from: private */
  348. public static AccessToken createFromBundle(List<String> list, Bundle bundle, AccessTokenSource accessTokenSource, Date date, String str) {
  349. Bundle bundle2 = bundle;
  350. String string = bundle.getString("access_token");
  351. Date bundleLongAsDate = Utility.getBundleLongAsDate(bundle, EXPIRES_IN_KEY, date);
  352. String string2 = bundle.getString("user_id");
  353. Date bundleLongAsDate2 = Utility.getBundleLongAsDate(bundle, DATA_ACCESS_EXPIRATION_TIME, new Date(0));
  354. if (Utility.isNullOrEmpty(string) || bundleLongAsDate == null) {
  355. return null;
  356. }
  357. AccessToken accessToken = new AccessToken(string, str, string2, list, null, null, accessTokenSource, bundleLongAsDate, new Date(), bundleLongAsDate2);
  358. return accessToken;
  359. }
  360.  
  361. private String tokenToString() {
  362. if (this.token == null) {
  363. return "null";
  364. }
  365. return FacebookSdk.isLoggingBehaviorEnabled(LoggingBehavior.INCLUDE_ACCESS_TOKENS) ? this.token : "ACCESS_TOKEN_REMOVED";
  366. }
  367.  
  368. private void appendPermissions(StringBuilder sb) {
  369. sb.append(" permissions:");
  370. if (this.f11permissions == null) {
  371. sb.append("null");
  372. return;
  373. }
  374. sb.append("[");
  375. sb.append(TextUtils.join(", ", this.f11permissions));
  376. sb.append("]");
  377. }
  378.  
  379. AccessToken(Parcel parcel) {
  380. this.expires = new Date(parcel.readLong());
  381. ArrayList arrayList = new ArrayList();
  382. parcel.readStringList(arrayList);
  383. this.f11permissions = Collections.unmodifiableSet(new HashSet(arrayList));
  384. arrayList.clear();
  385. parcel.readStringList(arrayList);
  386. this.declinedPermissions = Collections.unmodifiableSet(new HashSet(arrayList));
  387. arrayList.clear();
  388. parcel.readStringList(arrayList);
  389. this.expiredPermissions = Collections.unmodifiableSet(new HashSet(arrayList));
  390. this.token = parcel.readString();
  391. this.source = AccessTokenSource.valueOf(parcel.readString());
  392. this.lastRefresh = new Date(parcel.readLong());
  393. this.applicationId = parcel.readString();
  394. this.userId = parcel.readString();
  395. this.dataAccessExpirationTime = new Date(parcel.readLong());
  396. }
  397.  
  398. public void writeToParcel(Parcel parcel, int i) {
  399. parcel.writeLong(this.expires.getTime());
  400. parcel.writeStringList(new ArrayList(this.f11permissions));
  401. parcel.writeStringList(new ArrayList(this.declinedPermissions));
  402. parcel.writeStringList(new ArrayList(this.expiredPermissions));
  403. parcel.writeString(this.token);
  404. parcel.writeString(this.source.name());
  405. parcel.writeLong(this.lastRefresh.getTime());
  406. parcel.writeString(this.applicationId);
  407. parcel.writeString(this.userId);
  408. parcel.writeLong(this.dataAccessExpirationTime.getTime());
  409. }
  410. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×