package com.google.android.gms.common.api;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import com.google.android.gms.common.annotation.KeepName;
import p138.p176.p177.p242.p246.C4191;
import p138.p176.p177.p242.p246.C4194;
import p138.p176.p177.p242.p246.p247.p248.C4217;

/* JADX INFO: loaded from: classes.dex */
@KeepName
public class GoogleApiActivity extends Activity implements DialogInterface.OnCancelListener {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public int f2072 = 0;

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static PendingIntent m1331(Context context, PendingIntent pendingIntent, int i) {
        Intent intent = new Intent(context, (Class<?>) GoogleApiActivity.class);
        intent.putExtra("pending_intent", pendingIntent);
        intent.putExtra("failing_client_id", i);
        intent.putExtra("notify_manager", true);
        return PendingIntent.getActivity(context, 0, intent, 134217728);
    }

    @Override // android.app.Activity
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i == 1) {
            boolean booleanExtra = getIntent().getBooleanExtra("notify_manager", true);
            this.f2072 = 0;
            setResult(i2, intent);
            if (booleanExtra) {
                C4217 c4217M6880 = C4217.m6880(this);
                if (i2 == -1) {
                    Handler handler = c4217M6880.f13436;
                    handler.sendMessage(handler.obtainMessage(3));
                } else if (i2 == 0) {
                    C4191 c4191 = new C4191(13, null);
                    int intExtra = getIntent().getIntExtra("failing_client_id", -1);
                    if (!c4217M6880.m6882(c4191, intExtra)) {
                        Handler handler2 = c4217M6880.f13436;
                        handler2.sendMessage(handler2.obtainMessage(5, intExtra, 0, c4191));
                    }
                }
            }
        } else if (i == 2) {
            this.f2072 = 0;
            setResult(i2, intent);
        }
        finish();
    }

    @Override // android.content.DialogInterface.OnCancelListener
    public void onCancel(DialogInterface dialogInterface) {
        this.f2072 = 0;
        setResult(0);
        finish();
    }

    @Override // android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (bundle != null) {
            this.f2072 = bundle.getInt("resolution");
        }
        if (this.f2072 != 1) {
            Bundle extras = getIntent().getExtras();
            if (extras == null) {
                Log.e("GoogleApiActivity", "Activity started without extras");
                finish();
                return;
            }
            PendingIntent pendingIntent = (PendingIntent) extras.get("pending_intent");
            Integer num = (Integer) extras.get("error_code");
            if (pendingIntent == null && num == null) {
                Log.e("GoogleApiActivity", "Activity started without resolution");
                finish();
            } else {
                if (pendingIntent == null) {
                    C4194.f13402.m6848(this, num.intValue(), 2, this);
                    this.f2072 = 1;
                    return;
                }
                try {
                    startIntentSenderForResult(pendingIntent.getIntentSender(), 1, null, 0, 0, 0);
                    this.f2072 = 1;
                } catch (IntentSender.SendIntentException e) {
                    Log.e("GoogleApiActivity", "Failed to launch pendingIntent", e);
                    finish();
                }
            }
        }
    }

    @Override // android.app.Activity
    public void onSaveInstanceState(Bundle bundle) {
        bundle.putInt("resolution", this.f2072);
        super.onSaveInstanceState(bundle);
    }
}
