导航菜单

页面标题

页面副标题

Vi App v10.18.0 - AuthActivity.java 源代码

正在查看: Vi App v10.18.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.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.browser.customtabs.CustomTabColorSchemeParams;
import androidx.browser.customtabs.CustomTabsIntent;
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.R;
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 b;
    public Runnable c;
    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 (!com.amazon.apay.hardened.activity.c.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(R.id.cancelBtn).setVisibility(0);
    }

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

    public void d(String str) {
        findViewById(R.id.cancelBtn).setVisibility(0);
        InstrumentUtil.addMetricEvent("DelayedCancel", "LWA_LITE_SDK.BUSINESS_METRICS", str);
    }

    public final void onBackPressed() {
        a.a aVar = this.b;
        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.b.f = true;
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putSerializable("AUTH_STATUS", "DENIED");
        intent.putExtras(bundle);
        a(intent, 0, this.b.g);
    }

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

    public final void onCreate(Bundle bundle) {
        super/*androidx.fragment.app.FragmentActivity*/.onCreate(bundle);
        Bundle extras = getIntent().getExtras();
        final String string = bundle != null ? bundle.getString("stitchingId") : getIntent().getExtras() != null ? getIntent().getStringExtra("stitchingId") : UUID.randomUUID().toString();
        if (com.amazon.apay.hardened.activity.c.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(R.layout.activity_browser_apay);
        ((TextView) findViewById(R.id.loading_text)).setText(R.string.processing_text);
        this.d = new Runnable() {
            @Override
            public final void run() {
                AuthActivity.this.b();
            }
        };
        this.c = new Runnable() {
            @Override
            public final void run() {
                AuthActivity.this.d(string);
            }
        };
        InstrumentUtil.addMetricEvent("OnCreateCalled", "LWA_LITE_SDK.AUTH_ACTIVITY_OPERATION", string);
    }

    public final void onDestroy() {
        this.b = null;
        int i = R.id.cancelBtn;
        if (androidx.mediarouter.media.b.a(findViewById(i))) {
            findViewById(i).setVisibility(4);
        }
        this.g.removeCallbacks(this.d);
        this.g.removeCallbacks(this.c);
        Thread.setDefaultUncaughtExceptionHandler(this.f.getPrevDefaultExceptionHandler());
        this.f.tearDown();
        this.f = null;
        super.onDestroy();
    }

    public final void onNewIntent(Intent intent) {
        super/*androidx.activity.ComponentActivity*/.onNewIntent(intent);
        setIntent(intent);
        a.a aVar = this.b;
        aVar.c = true;
        InstrumentUtil.addMetricEvent("OnNewIntentCalled", "LWA_LITE_SDK.AUTH_ACTIVITY_OPERATION", aVar.g);
    }

    public final void onResume() {
        super/*androidx.fragment.app.FragmentActivity*/.onResume();
        a.a aVar = this.b;
        String str = aVar.g;
        boolean z = true;
        if (aVar.i.intValue() > 1) {
            InstrumentUtil.addMetricEvent("AppSwitchDone", "LWA_LITE_SDK.BUSINESS_METRICS", str);
        }
        if (!this.b.b) {
            this.g.postDelayed(this.c, 12000L);
            InstrumentUtil.addMetricEvent("AuthInitialize", "LWA_LITE_SDK.AUTH_OPERATION", this.b.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.b.j)).shouldReturnUserData(false).forGrantType(AuthorizeRequest.GrantType.AUTHORIZATION_CODE).withProofKeyParameters(this.b.a, "S256").splitSignInForSubRegion(Constants.AuthConstants.b).build();
                AuthorizationManager.setRegion(this, Constants.AuthConstants.a);
                AuthorizationManager.authorize(build2);
            } catch (Exception e) {
                if (Objects.equals(e.getMessage(), "Invalid API Key")) {
                    a("INVALID_API_KEY_ERROR", "Invalid API key provided", this.b.g);
                } else {
                    a("AUTH_FAILURE", "Authorisation failed", this.b.g);
                }
            }
            this.b.b = 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.b.g);
        }
        a.a aVar2 = this.b;
        boolean z2 = aVar2.c;
        if (aVar2.d && androidx.mediarouter.media.b.a(Boolean.valueOf(z2)) && !z2) {
            this.g.postDelayed(this.d, 6000L);
        }
        RequestContext requestContext = this.e;
        if (requestContext != null) {
            requestContext.onResume();
            return;
        }
        String stringExtra = getIntent().getStringExtra("authResponse");
        if (!androidx.mediarouter.media.b.a(stringExtra)) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public final void run() {
                    AuthActivity.this.c();
                }
            }, 200L);
            return;
        }
        try {
            a(stringExtra);
        } catch (AuthError e2) {
            if (com.amazon.apay.hardened.activity.c.a(this.b) && androidx.mediarouter.media.b.a(getIntent().getExtras())) {
                a(getIntent().getExtras());
                InstrumentUtil.addMetricEvent("ListenerInvokedAfterActivityDestroyed", "LWA_LITE_SDK.AUTH_RESPONSE", this.b.g);
            }
            a.a aVar3 = this.b;
            String str2 = aVar3.g;
            if (aVar3.e || aVar3.f) {
                InstrumentUtil.addMetricEvent("FalseLoginFailed", "LWA_LITE_SDK.AUTH_RESPONSE", str2);
            } else {
                z = false;
            }
            if (z) {
                return;
            }
            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.b.g);
        }
    }

    public final void onSaveInstanceState(@NonNull Bundle bundle) {
        super/*androidx.activity.ComponentActivity*/.onSaveInstanceState(bundle);
        InstrumentUtil.addMetricEvent("SaveStateSuccess", "LWA_LITE_SDK.AUTH_ACTIVITY_OPERATION", this.b.g);
        bundle.putParcelable("AuthRequest", this.b);
    }

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

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

    public void c(final String str) {
        ((TextView) findViewById(R.id.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.b.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(@NonNull 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 parcelable = bundle.getParcelable("AuthRequest");
        this.b = parcelable;
        if (com.amazon.apay.hardened.activity.c.a(parcelable)) {
            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) {
        boolean z = true;
        String.format("LWAAuthorizeListener:onSuccess invoked: %s", authorizeResult);
        if (com.amazon.apay.hardened.activity.c.a(this.b) && androidx.mediarouter.media.b.a(getIntent().getExtras())) {
            a(getIntent().getExtras());
            InstrumentUtil.addMetricEvent("ListenerInvokedAfterActivityDestroyed", "LWA_LITE_SDK.AUTH_RESPONSE", this.b.g);
        }
        a.a aVar = this.b;
        if (aVar.e || aVar.f) {
            InstrumentUtil.addMetricEvent("FalseLoginSuccess", "LWA_LITE_SDK.AUTH_RESPONSE", aVar.g);
        } else {
            z = false;
        }
        if (z) {
            return;
        }
        boolean z2 = this.b.c;
        if (androidx.mediarouter.media.b.a(Boolean.valueOf(z2)) && z2) {
            InstrumentUtil.addMetricEvent("CCTAuthSuccess", "LWA_LITE_SDK.AUTH_RESPONSE", this.b.g);
        } else {
            InstrumentUtil.addMetricEvent("SSOAuthSuccess", "LWA_LITE_SDK.AUTH_RESPONSE", this.b.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.b.g);
    }

    public final void a(AuthCancellation authCancellation) {
        boolean z = true;
        String.format("LWAAuthorizeListener: onCancel called %s", authCancellation.toString());
        if (com.amazon.apay.hardened.activity.c.a(this.b) && androidx.mediarouter.media.b.a(getIntent().getExtras())) {
            a(getIntent().getExtras());
            InstrumentUtil.addMetricEvent("ListenerInvokedAfterActivityDestroyed", "LWA_LITE_SDK.AUTH_RESPONSE", this.b.g);
        }
        a.a aVar = this.b;
        String str = aVar.g;
        if (aVar.e || aVar.f) {
            InstrumentUtil.addMetricEvent("FalseLoginCanceled", "LWA_LITE_SDK.AUTH_RESPONSE", str);
        } else {
            z = false;
        }
        if (z) {
            return;
        }
        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.b.g);
            return;
        }
        Intent intent2 = new Intent();
        Bundle bundle2 = new Bundle();
        bundle2.putSerializable("AUTH_STATUS", "FAILURE");
        intent2.putExtras(bundle2);
        a(intent2, -1, this.b.g);
    }

    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.b.g);
            a("AUTH_FAILURE", "Authorisation failed", this.b.g);
        } else {
            if (TextUtils.isEmpty(extractResultsBundle.getString("code"))) {
                InstrumentUtil.addMetricEvent("EmptyCode", "LWA_LITE_SDK.AUTH_RESPONSE", this.b.g);
                a("AUTH_FAILURE", "Authorisation failed", this.b.g);
                return;
            }
            Bundle bundle = new Bundle();
            bundle.putString(AuthzConstants.BUNDLE_KEY.AUTHORIZATION_CODE.val, extractResultsBundle.getString("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) {
        boolean z;
        if (com.amazon.apay.hardened.activity.c.a(this.b) && androidx.mediarouter.media.b.a(getIntent().getExtras())) {
            a(getIntent().getExtras());
            InstrumentUtil.addMetricEvent("ListenerInvokedAfterActivityDestroyed", "LWA_LITE_SDK.AUTH_RESPONSE", this.b.g);
        }
        a.a aVar = this.b;
        String str = aVar.g;
        if (aVar.e || aVar.f) {
            InstrumentUtil.addMetricEvent("FalseLoginFailed", "LWA_LITE_SDK.AUTH_RESPONSE", str);
            z = true;
        } else {
            z = false;
        }
        if (z) {
            return;
        }
        InstrumentUtil.addMetricEvent("AuthError", "LWA_LITE_SDK.AUTH_RESPONSE", str);
        a("START_BROWSING_ERROR", authError.getMessage(), str);
    }
}