package com.google.firebase.messaging;

import android.content.res.Resources;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import java.util.Arrays;
import java.util.MissingFormatArgumentException;
import org.json.JSONArray;
import org.json.JSONException;

/* JADX INFO: loaded from: classes2.dex */
public final class t {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Bundle f24259a;

    public t(Bundle bundle) {
        if (bundle == null) {
            throw new NullPointerException("data");
        }
        this.f24259a = new Bundle(bundle);
    }

    public static boolean d(Bundle bundle) {
        return "1".equals(bundle.getString("gcm.n.e")) || "1".equals(bundle.getString("gcm.n.e".replace("gcm.n.", "gcm.notification.")));
    }

    public static void f(String str) {
        if (str.startsWith("gcm.n.")) {
            str.substring(6);
        }
    }

    public final boolean a(String str) {
        String strC = c(str);
        return "1".equals(strC) || Boolean.parseBoolean(strC);
    }

    public final Integer b(String str) {
        String strC = c(str);
        if (TextUtils.isEmpty(strC)) {
            return null;
        }
        try {
            return Integer.valueOf(Integer.parseInt(strC));
        } catch (NumberFormatException unused) {
            f(str);
            return null;
        }
    }

    public final String c(String str) {
        Bundle bundle = this.f24259a;
        if (!bundle.containsKey(str) && str.startsWith("gcm.n.")) {
            String strReplace = !str.startsWith("gcm.n.") ? str : str.replace("gcm.n.", "gcm.notification.");
            if (bundle.containsKey(strReplace)) {
                str = strReplace;
            }
        }
        return bundle.getString(str);
    }

    public final Bundle e() {
        Bundle bundle = this.f24259a;
        Bundle bundle2 = new Bundle(bundle);
        for (String str : bundle.keySet()) {
            if (!str.startsWith("google.c.a.") && !str.equals("from")) {
                bundle2.remove(str);
            }
        }
        return bundle2;
    }

    @Nullable
    public JSONArray getJSONArray(String str) {
        String strC = c(str);
        if (TextUtils.isEmpty(strC)) {
            return null;
        }
        try {
            return new JSONArray(strC);
        } catch (JSONException unused) {
            f(str);
            return null;
        }
    }

    @Nullable
    public int[] getLightSettings() {
        JSONArray jSONArray = getJSONArray("gcm.n.light_settings");
        if (jSONArray == null) {
            return null;
        }
        int[] iArr = new int[3];
        try {
            if (jSONArray.length() != 3) {
                throw new JSONException("lightSettings don't have all three fields");
            }
            int color = Color.parseColor(jSONArray.optString(0));
            if (color == -16777216) {
                throw new IllegalArgumentException("Transparent color is invalid");
            }
            iArr[0] = color;
            iArr[1] = jSONArray.optInt(1);
            iArr[2] = jSONArray.optInt(2);
            return iArr;
        } catch (IllegalArgumentException e10) {
            jSONArray.toString();
            e10.getMessage();
            return null;
        } catch (JSONException unused) {
            jSONArray.toString();
            return null;
        }
    }

    @Nullable
    public Uri getLink() {
        String strC = c("gcm.n.link_android");
        if (TextUtils.isEmpty(strC)) {
            strC = c("gcm.n.link");
        }
        if (TextUtils.isEmpty(strC)) {
            return null;
        }
        return Uri.parse(strC);
    }

    @Nullable
    public Object[] getLocalizationArgsForKey(String str) {
        JSONArray jSONArray = getJSONArray(str + "_loc_args");
        if (jSONArray == null) {
            return null;
        }
        int length = jSONArray.length();
        String[] strArr = new String[length];
        for (int i10 = 0; i10 < length; i10++) {
            strArr[i10] = jSONArray.optString(i10);
        }
        return strArr;
    }

    @Nullable
    public String getLocalizationResourceForKey(String str) {
        return c(str + "_loc_key");
    }

    @Nullable
    public String getLocalizedString(Resources resources, String str, String str2) {
        String localizationResourceForKey = getLocalizationResourceForKey(str2);
        if (TextUtils.isEmpty(localizationResourceForKey)) {
            return null;
        }
        int identifier = resources.getIdentifier(localizationResourceForKey, "string", str);
        if (identifier == 0) {
            f(str2 + "_loc_key");
            return null;
        }
        Object[] localizationArgsForKey = getLocalizationArgsForKey(str2);
        if (localizationArgsForKey == null) {
            return resources.getString(identifier);
        }
        try {
            return resources.getString(identifier, localizationArgsForKey);
        } catch (MissingFormatArgumentException unused) {
            f(str2);
            Arrays.toString(localizationArgsForKey);
            return null;
        }
    }

    @Nullable
    public Integer getNotificationCount() {
        Integer numB = b("gcm.n.notification_count");
        if (numB != null && numB.intValue() >= 0) {
            return numB;
        }
        return null;
    }

    @Nullable
    public Integer getNotificationPriority() {
        Integer numB = b("gcm.n.notification_priority");
        if (numB != null && numB.intValue() >= -2 && numB.intValue() <= 2) {
            return numB;
        }
        return null;
    }

    @Nullable
    public String getSoundResourceName() {
        String strC = c("gcm.n.sound2");
        return TextUtils.isEmpty(strC) ? c("gcm.n.sound") : strC;
    }

    @Nullable
    public long[] getVibrateTimings() {
        JSONArray jSONArray = getJSONArray("gcm.n.vibrate_timings");
        if (jSONArray == null) {
            return null;
        }
        try {
            if (jSONArray.length() <= 1) {
                throw new JSONException("vibrateTimings have invalid length");
            }
            int length = jSONArray.length();
            long[] jArr = new long[length];
            for (int i10 = 0; i10 < length; i10++) {
                jArr[i10] = jSONArray.optLong(i10);
            }
            return jArr;
        } catch (NumberFormatException | JSONException unused) {
            jSONArray.toString();
            return null;
        }
    }
}
