导航菜单

页面标题

页面副标题

bbinstant v6.24.0 - AuthActivity.java 源代码

正在查看: bbinstant v6.24.0 应用的 AuthActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.amazon.identity.auth.apay.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.browser.customtabs.CustomTabColorSchemeParams;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.util.j;
import androidx.fragment.app.FragmentActivity;
import com.amazon.android.apay.commonlibrary.commonlib.exception.ApayUncaughtExceptionHandler;
import com.amazon.android.apay.commonlibrary.commonlib.utils.InstrumentUtil;
import com.amazon.android.apay.commonlibrary.interfaces.external.MerchantConstants;
import com.amazon.android.apay.commonlibrary.interfaces.model.AmazonPayError;
import com.amazon.identity.auth.device.AuthError;
import com.amazon.identity.auth.device.Constants;
import com.amazon.identity.auth.device.api.authorization.AuthCancellation;
import com.amazon.identity.auth.device.api.authorization.AuthorizationManager;
import com.amazon.identity.auth.device.api.authorization.AuthorizeListener;
import com.amazon.identity.auth.device.api.authorization.AuthorizeRequest;
import com.amazon.identity.auth.device.api.authorization.AuthorizeResult;
import com.amazon.identity.auth.device.api.authorization.Scope;
import com.amazon.identity.auth.device.api.authorization.ScopeFactory;
import com.amazon.identity.auth.device.api.workflow.RequestContext;
import com.amazon.identity.auth.device.authorization.AuthorizationResponseParser;
import com.amazon.identity.auth.device.authorization.InternalAuthManager;
import com.amazon.identity.auth.device.authorization.ServiceConnectionState;
import com.amazon.identity.auth.device.authorization.ThirdPartyAuthorizationHelper;
import com.amazon.identity.auth.device.authorization.api.AuthzConstants;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class AuthActivity extends AppCompatActivity {
    public static CustomTabsIntent h;

    public a.a f368b;

    public Runnable f369c;
    public Runnable d;
    public RequestContext e;
    public ApayUncaughtExceptionHandler f;
    public final Handler g = new Handler();

    public final class a extends AuthorizeListener {
        public a() {
        }

        @Override
        public final void onCancel(Object obj) {
            AuthActivity.this.a((AuthCancellation) obj);
        }

        @Override
        public final void onError(AuthError authError) {
            AuthActivity authActivity = AuthActivity.this;
            CustomTabsIntent customTabsIntent = AuthActivity.h;
            authActivity.a(authError);
        }

        @Override
        public final void onSuccess(AuthorizeResult authorizeResult) {
            AuthActivity authActivity = AuthActivity.this;
            CustomTabsIntent customTabsIntent = AuthActivity.h;
            authActivity.a(authorizeResult);
        }

        @Override
        public final void onCancel(AuthCancellation authCancellation) {
            AuthActivity.this.a(authCancellation);
        }
    }

    public static Scope[] a(List list) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(ScopeFactory.scopeNamed("payments::conduct_silentpay"));
        arrayList.add(ScopeFactory.scopeNamed("profile:user_id"));
        if (!j.a(list) && !list.isEmpty()) {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                arrayList.add(ScopeFactory.scopeNamed((String) it.next()));
            }
        }
        return (Scope[]) arrayList.toArray(new Scope[arrayList.size()]);
    }

    public void b() {
        findViewById(com.amazon.identity.auth.device.authorization.a.cancelBtn).setVisibility(0);
    }

    public void c() {
        if (isFinishing() || ThirdPartyAuthorizationHelper.serviceStatus != ServiceConnectionState.UNINITIATED) {
            return;
        }
        a();
    }

    public void d(String str) {
        findViewById(com.amazon.identity.auth.device.authorization.a.cancelBtn).setVisibility(0);
        InstrumentUtil.addMetricEvent("DelayedCancel", "LWA_LITE_SDK.BUSINESS_METRICS", str);
    }

    @Override
    public final void onBackPressed() {
        a.a aVar = this.f368b;
        if (aVar.e) {
            InstrumentUtil.addMetricEvent("BackBtnClickAfterCancel", "LWA_LITE_SDK.AUTH_RESPONSE", aVar.g);
            return;
        }
        InstrumentUtil.addMetricEvent("BackBtnClick", "LWA_LITE_SDK.AUTH_RESPONSE", aVar.g);
        this.f368b.f = true;
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putSerializable("AUTH_STATUS", "DENIED");
        intent.putExtras(bundle);
        a(intent, 0, this.f368b.g);
    }

    public void onCancelBtnClick(View view) {
        a.a aVar = this.f368b;
        aVar.e = true;
        InstrumentUtil.addMetricEvent("CancelBtnClick", "LWA_LITE_SDK.AUTH_RESPONSE", aVar.g);
        findViewById(com.amazon.identity.auth.device.authorization.a.cancelBtn).setVisibility(4);
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putSerializable("AUTH_STATUS", "DENIED");
        intent.putExtras(bundle);
        a(intent, -1, this.f368b.g);
    }

    @Override
    public final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        Bundle extras = getIntent().getExtras();
        final String string = bundle != null ? bundle.getString("stitchingId") : getIntent().getExtras() != null ? getIntent().getStringExtra("stitchingId") : UUID.randomUUID().toString();
        if (j.a(extras)) {
            a("INVALID_REQUEST", "Invalid request", string);
        }
        ApayUncaughtExceptionHandler apayUncaughtExceptionHandler = new ApayUncaughtExceptionHandler(this, string);
        this.f = apayUncaughtExceptionHandler;
        Thread.setDefaultUncaughtExceptionHandler(apayUncaughtExceptionHandler);
        if (bundle == null || bundle.isEmpty()) {
            a(getIntent().getExtras());
        } else {
            a(bundle);
        }
        setContentView(com.amazon.identity.auth.device.authorization.b.activity_browser_apay);
        ((TextView) findViewById(com.amazon.identity.auth.device.authorization.a.loading_text)).setText(com.amazon.identity.auth.device.authorization.c.processing_text);
        this.d = new Runnable() {
            @Override
            public final void run() {
                AuthActivity.this.b();
            }
        };
        this.f369c = new Runnable() {
            @Override
            public final void run() {
                AuthActivity.this.d(string);
            }
        };
        InstrumentUtil.addMetricEvent("OnCreateCalled", "LWA_LITE_SDK.AUTH_ACTIVITY_OPERATION", string);
    }

    @Override
    public final void onDestroy() {
        this.f368b = null;
        int i = com.amazon.identity.auth.device.authorization.a.cancelBtn;
        if (com.amazon.identity.auth.apay.activity.a.a(findViewById(i))) {
            findViewById(i).setVisibility(4);
        }
        this.g.removeCallbacks(this.d);
        this.g.removeCallbacks(this.f369c);
        Thread.setDefaultUncaughtExceptionHandler(this.f.getPrevDefaultExceptionHandler());
        this.f.tearDown();
        this.f = null;
        super.onDestroy();
    }

    @Override
    public final void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        a.a aVar = this.f368b;
        aVar.f5c = true;
        InstrumentUtil.addMetricEvent("OnNewIntentCalled", "LWA_LITE_SDK.AUTH_ACTIVITY_OPERATION", aVar.g);
    }

    @Override
    public final void onResume() {
        super.onResume();
        a.a aVar = this.f368b;
        String str = aVar.g;
        if (aVar.i.intValue() > 1) {
            InstrumentUtil.addMetricEvent("AppSwitchDone", "LWA_LITE_SDK.BUSINESS_METRICS", str);
        }
        if (!this.f368b.f4b) {
            this.g.postDelayed(this.f369c, 12000L);
            InstrumentUtil.addMetricEvent("AuthInitialize", "LWA_LITE_SDK.AUTH_OPERATION", this.f368b.g);
            try {
                CustomTabsIntent build = new CustomTabsIntent.Builder().setShowTitle(true).setDefaultColorSchemeParams(new CustomTabColorSchemeParams.Builder().setToolbarColor(-1).build()).build();
                h = build;
                build.intent.setPackage("com.android.chrome");
                RequestContext create = RequestContext.create((FragmentActivity) this, getIntent(), h);
                this.e = create;
                create.registerListener(new a());
                AuthorizeRequest build2 = new AuthorizeRequest.Builder(this.e).addScopes(a(this.f368b.f6j)).shouldReturnUserData(false).forGrantType(AuthorizeRequest.GrantType.AUTHORIZATION_CODE).withProofKeyParameters(this.f368b.f3a, "S256").splitSignInForSubRegion(Constants.AuthConstants.f386b).build();
                AuthorizationManager.setRegion(this, Constants.AuthConstants.f385a);
                AuthorizationManager.authorize(build2);
            } catch (Exception e) {
                if (Objects.equals(e.getMessage(), "Invalid API Key")) {
                    a("INVALID_API_KEY_ERROR", "Invalid API key provided", this.f368b.g);
                } else {
                    a("AUTH_FAILURE", "Authorisation failed", this.f368b.g);
                }
            }
            this.f368b.f4b = true;
            return;
        }
        Intent intent = getIntent();
        if (intent.getData() != null) {
            InstrumentUtil.addMetricEvent("CCTAuthRedirectSuccess", "LWA_LITE_SDK.AUTH_OPERATION", str);
            String.format("AuthActivity:onResume with data:%s", intent.getData().toString());
            Bundle extras = intent.getExtras();
            extras.putSerializable("AUTH_STATUS", "GRANTED");
            intent.putExtras(extras);
            a(intent, -1, this.f368b.g);
        }
        a.a aVar2 = this.f368b;
        boolean z = aVar2.f5c;
        if (aVar2.d && com.amazon.identity.auth.apay.activity.a.a(Boolean.valueOf(z)) && !z) {
            this.g.postDelayed(this.d, 6000L);
        }
        RequestContext requestContext = this.e;
        if (requestContext != null) {
            requestContext.onResume();
            return;
        }
        String stringExtra = getIntent().getStringExtra("authResponse");
        if (!com.amazon.identity.auth.apay.activity.a.a(stringExtra)) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public final void run() {
                    AuthActivity.this.c();
                }
            }, 200L);
            return;
        }
        try {
            a(stringExtra);
        } catch (AuthError e2) {
            if (j.a(this.f368b) && com.amazon.identity.auth.apay.activity.a.a(getIntent().getExtras())) {
                a(getIntent().getExtras());
                InstrumentUtil.addMetricEvent("ListenerInvokedAfterActivityDestroyed", "LWA_LITE_SDK.AUTH_RESPONSE", this.f368b.g);
            }
            a.a aVar3 = this.f368b;
            String str2 = aVar3.g;
            if (aVar3.e || aVar3.f) {
                InstrumentUtil.addMetricEvent("FalseLoginFailed", "LWA_LITE_SDK.AUTH_RESPONSE", str2);
            } else {
                InstrumentUtil.addMetricEvent("AuthError", "LWA_LITE_SDK.AUTH_RESPONSE", str2);
                a("START_BROWSING_ERROR", e2.getMessage(), str2);
            }
        } catch (Exception unused) {
            a("AUTH_FAILURE", "Authorisation failed", this.f368b.g);
        }
    }

    @Override
    public final void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        InstrumentUtil.addMetricEvent("SaveStateSuccess", "LWA_LITE_SDK.AUTH_ACTIVITY_OPERATION", this.f368b.g);
        bundle.putParcelable("AuthRequest", this.f368b);
    }

    @Override
    public final void onStop() {
        a.a aVar = this.f368b;
        aVar.d = true;
        aVar.i = Integer.valueOf(aVar.i.intValue() + 1);
        this.g.removeCallbacks(this.f369c);
        super.onStop();
    }

    public void b(String str) {
        InstrumentUtil.addMetricEvent("LoginDroppedOff", "LWA_LITE_SDK.BUSINESS_METRICS", this.f368b.g);
        a(str, "Auth cancelled", this.f368b.g);
    }

    public void c(final String str) {
        ((TextView) findViewById(com.amazon.identity.auth.device.authorization.a.loading_text)).setText("Canceling your Amazon Pay authorization");
        new Handler().postDelayed(new Runnable() {
            @Override
            public final void run() {
                AuthActivity.this.b(str);
            }
        }, 1000L);
    }

    public final void a() {
        this.f368b.e = true;
        final String str = "AuthCancelled";
        runOnUiThread(new Runnable() {
            @Override
            public final void run() {
                AuthActivity.this.c(str);
            }
        });
    }

    public final void a(String str, String str2, String str3) {
        InstrumentUtil.addMetricEvent(str, str2, str3);
        AmazonPayError amazonPayError = new AmazonPayError(MerchantConstants.AUTH_ERROR, str);
        Bundle bundle = new Bundle();
        bundle.putParcelable(MerchantConstants.ERROR, amazonPayError);
        a(new Intent().putExtras(bundle), 0, str3);
    }

    public final void a(Intent intent, int i, String str) {
        String.format("AuthActivity:handleOperationComplete invoked with data : %s", intent.toString());
        InstrumentUtil.addMetricEvent("AUTHORIZE.OperationCompleted", "AUTHORIZE", str);
        setResult(i, intent);
        InstrumentUtil.addMetricEvent("AuthComplete", "LWA_LITE_SDK.BUSINESS_METRICS", str);
        finish();
    }

    public final void a(Bundle bundle) {
        String uuid;
        if (bundle != null) {
            uuid = bundle.getString("stitchingId");
        } else if (getIntent().getExtras() != null) {
            uuid = getIntent().getStringExtra("stitchingId");
        } else {
            uuid = UUID.randomUUID().toString();
        }
        a.a aVar = (a.a) bundle.getParcelable("AuthRequest");
        this.f368b = aVar;
        if (j.a(aVar)) {
            InstrumentUtil.addMetricEvent("ExtractStateFailed", "LWA_LITE_SDK.AUTH_ACTIVITY_OPERATION", uuid);
            a("AUTH_FAILURE", "NullAuthRequestExtracted", uuid);
        }
        InstrumentUtil.addMetricEvent("ExtractStateSuccess", "LWA_LITE_SDK.AUTH_ACTIVITY_OPERATION", uuid);
    }

    public final void a(AuthorizeResult authorizeResult) {
        String.format("LWAAuthorizeListener:onSuccess invoked: %s", authorizeResult);
        if (j.a(this.f368b) && com.amazon.identity.auth.apay.activity.a.a(getIntent().getExtras())) {
            a(getIntent().getExtras());
            InstrumentUtil.addMetricEvent("ListenerInvokedAfterActivityDestroyed", "LWA_LITE_SDK.AUTH_RESPONSE", this.f368b.g);
        }
        a.a aVar = this.f368b;
        if (!aVar.e && !aVar.f) {
            boolean z = aVar.f5c;
            if (com.amazon.identity.auth.apay.activity.a.a(Boolean.valueOf(z)) && z) {
                InstrumentUtil.addMetricEvent("CCTAuthSuccess", "LWA_LITE_SDK.AUTH_RESPONSE", this.f368b.g);
            } else {
                InstrumentUtil.addMetricEvent("SSOAuthSuccess", "LWA_LITE_SDK.AUTH_RESPONSE", this.f368b.g);
            }
            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putSerializable("authCode", authorizeResult.getAuthorizationCode());
            bundle.putSerializable("lwaClientId", authorizeResult.getClientId());
            bundle.putSerializable(AuthorizationResponseParser.REDIRECT_URI_STATE, authorizeResult.getRedirectURI());
            intent.putExtras(bundle);
            Bundle extras = intent.getExtras();
            extras.putSerializable("AUTH_STATUS", "GRANTED");
            intent.putExtras(extras);
            a(intent, -1, this.f368b.g);
            return;
        }
        InstrumentUtil.addMetricEvent("FalseLoginSuccess", "LWA_LITE_SDK.AUTH_RESPONSE", aVar.g);
    }

    public final void a(AuthCancellation authCancellation) {
        String.format("LWAAuthorizeListener: onCancel called %s", authCancellation.toString());
        if (j.a(this.f368b) && com.amazon.identity.auth.apay.activity.a.a(getIntent().getExtras())) {
            a(getIntent().getExtras());
            InstrumentUtil.addMetricEvent("ListenerInvokedAfterActivityDestroyed", "LWA_LITE_SDK.AUTH_RESPONSE", this.f368b.g);
        }
        a.a aVar = this.f368b;
        String str = aVar.g;
        if (!aVar.e && !aVar.f) {
            InstrumentUtil.addMetricEvent("AuthCancelled", "LWA_LITE_SDK.AUTH_RESPONSE", str);
            if (authCancellation.getCause() == AuthCancellation.Cause.FAILED_AUTHENTICATION) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putSerializable("AUTH_STATUS", "DENIED");
                intent.putExtras(bundle);
                a(intent, -1, this.f368b.g);
                return;
            }
            Intent intent2 = new Intent();
            Bundle bundle2 = new Bundle();
            bundle2.putSerializable("AUTH_STATUS", "FAILURE");
            intent2.putExtras(bundle2);
            a(intent2, -1, this.f368b.g);
            return;
        }
        InstrumentUtil.addMetricEvent("FalseLoginCanceled", "LWA_LITE_SDK.AUTH_RESPONSE", str);
    }

    public final void a(String str) throws AuthError {
        Bundle extractResultsBundle = new AuthorizationResponseParser().extractResultsBundle(str, (String[]) null);
        if (extractResultsBundle.containsKey(AuthzConstants.BUNDLE_KEY.CAUSE_ID.val)) {
            a(new AuthCancellation(extractResultsBundle));
            return;
        }
        if (!extractResultsBundle.getBoolean(AuthzConstants.BUNDLE_KEY.GET_AUTH_CODE.val, false)) {
            InstrumentUtil.addMetricEvent("ReturnAuthCodeFalse", "LWA_LITE_SDK.AUTH_RESPONSE", this.f368b.g);
            a("AUTH_FAILURE", "Authorisation failed", this.f368b.g);
        } else {
            if (TextUtils.isEmpty(extractResultsBundle.getString(AuthorizationResponseParser.CODE))) {
                InstrumentUtil.addMetricEvent("EmptyCode", "LWA_LITE_SDK.AUTH_RESPONSE", this.f368b.g);
                a("AUTH_FAILURE", "Authorisation failed", this.f368b.g);
                return;
            }
            Bundle bundle = new Bundle();
            bundle.putString(AuthzConstants.BUNDLE_KEY.AUTHORIZATION_CODE.val, extractResultsBundle.getString(AuthorizationResponseParser.CODE));
            bundle.putString(AuthzConstants.BUNDLE_KEY.CLIENT_ID.val, InternalAuthManager.getInstance(this).getClientId());
            bundle.putString(AuthzConstants.BUNDLE_KEY.REDIRECT_URI.val, InternalAuthManager.getInstance(this).getRedirectURI(this));
            a(new AuthorizeResult(bundle));
        }
    }

    public final void a(AuthError authError) {
        if (j.a(this.f368b) && com.amazon.identity.auth.apay.activity.a.a(getIntent().getExtras())) {
            a(getIntent().getExtras());
            InstrumentUtil.addMetricEvent("ListenerInvokedAfterActivityDestroyed", "LWA_LITE_SDK.AUTH_RESPONSE", this.f368b.g);
        }
        a.a aVar = this.f368b;
        String str = aVar.g;
        if (!aVar.e && !aVar.f) {
            InstrumentUtil.addMetricEvent("AuthError", "LWA_LITE_SDK.AUTH_RESPONSE", str);
            a("START_BROWSING_ERROR", authError.getMessage(), str);
        } else {
            InstrumentUtil.addMetricEvent("FalseLoginFailed", "LWA_LITE_SDK.AUTH_RESPONSE", str);
        }
    }
}