package androidx.core.app;

import android.app.Notification;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.widget.RemoteViews;
import androidx.core.graphics.drawable.IconCompat;
import com.debridstream.tv.R;
import com.google.firebase.sessions.settings.RemoteSettings;
import com.revenuecat.purchases.common.Constants;

/* JADX INFO: loaded from: classes.dex */
public abstract class C {
    CharSequence mBigContentTitle;
    protected C1007n mBuilder;
    CharSequence mSummaryText;
    boolean mSummaryTextSet = false;

    public static C constructCompatStyleByName(String str) {
        if (str == null) {
            return null;
        }
        switch (str) {
            case "androidx.core.app.NotificationCompat$DecoratedCustomViewStyle":
                return new u();
            case "androidx.core.app.NotificationCompat$BigPictureStyle":
                return new C1005l();
            case "androidx.core.app.NotificationCompat$CallStyle":
                return new C1011s();
            case "androidx.core.app.NotificationCompat$InboxStyle":
                return new C1006m(1);
            case "androidx.core.app.NotificationCompat$BigTextStyle":
                return new C1006m(0);
            case "androidx.core.app.NotificationCompat$MessagingStyle":
                return new B();
            default:
                return null;
        }
    }

    public static C constructCompatStyleForBundle(Bundle bundle) {
        C cConstructCompatStyleByName = constructCompatStyleByName(bundle.getString("androidx.core.app.extra.COMPAT_TEMPLATE"));
        if (cConstructCompatStyleByName != null) {
            return cConstructCompatStyleByName;
        }
        if (bundle.containsKey("android.selfDisplayName") || bundle.containsKey("android.messagingStyleUser")) {
            return new B();
        }
        if (bundle.containsKey("android.picture") || bundle.containsKey("android.pictureIcon")) {
            return new C1005l();
        }
        if (bundle.containsKey("android.bigText")) {
            return new C1006m(0);
        }
        if (bundle.containsKey("android.textLines")) {
            return new C1006m(1);
        }
        if (bundle.containsKey("android.callType")) {
            return new C1011s();
        }
        String string = bundle.getString("android.template");
        if (string == null) {
            return null;
        }
        if (string.equals(Notification.BigPictureStyle.class.getName())) {
            return new C1005l();
        }
        if (string.equals(Notification.BigTextStyle.class.getName())) {
            return new C1006m(0);
        }
        if (string.equals(Notification.InboxStyle.class.getName())) {
            return new C1006m(1);
        }
        if (string.equals(Notification.MessagingStyle.class.getName())) {
            return new B();
        }
        if (string.equals(Notification.DecoratedCustomViewStyle.class.getName())) {
            return new u();
        }
        return null;
    }

    public static C constructStyleForExtras(Bundle bundle) {
        C cConstructCompatStyleForBundle = constructCompatStyleForBundle(bundle);
        if (cConstructCompatStyleForBundle == null) {
            return null;
        }
        try {
            cConstructCompatStyleForBundle.restoreFromCompatExtras(bundle);
            return cConstructCompatStyleForBundle;
        } catch (ClassCastException unused) {
            return null;
        }
    }

    public static C extractStyleFromNotification(Notification notification) {
        Bundle bundle = notification.extras;
        if (bundle == null) {
            return null;
        }
        return constructStyleForExtras(bundle);
    }

    public final Bitmap a(IconCompat iconCompat, int i6, int i7) {
        Object obj;
        ApplicationInfo applicationInfo;
        Resources resourcesForApplication;
        Context context = this.mBuilder.f11249a;
        if (iconCompat.f11291a == 2 && (obj = iconCompat.f11292b) != null) {
            String str = (String) obj;
            if (str.contains(Constants.SUBS_ID_BASE_PLAN_ID_SEPARATOR)) {
                String str2 = str.split(Constants.SUBS_ID_BASE_PLAN_ID_SEPARATOR, -1)[1];
                String str3 = str2.split(RemoteSettings.FORWARD_SLASH_STRING, -1)[0];
                String str4 = str2.split(RemoteSettings.FORWARD_SLASH_STRING, -1)[1];
                String str5 = str.split(Constants.SUBS_ID_BASE_PLAN_ID_SEPARATOR, -1)[0];
                if ("0_resource_name_obfuscated".equals(str4)) {
                    Log.i("IconCompat", "Found obfuscated resource, not trying to update resource id for it");
                } else {
                    String strF = iconCompat.f();
                    if ("android".equals(strF)) {
                        resourcesForApplication = Resources.getSystem();
                    } else {
                        PackageManager packageManager = context.getPackageManager();
                        try {
                            applicationInfo = packageManager.getApplicationInfo(strF, 8192);
                        } catch (PackageManager.NameNotFoundException e6) {
                            Log.e("IconCompat", "Unable to find pkg=" + strF + " for icon", e6);
                        }
                        resourcesForApplication = applicationInfo != null ? packageManager.getResourcesForApplication(applicationInfo) : null;
                    }
                    int identifier = resourcesForApplication.getIdentifier(str4, str3, str5);
                    if (iconCompat.f11295e != identifier) {
                        Log.i("IconCompat", "Id has changed for " + strF + " " + str);
                        iconCompat.f11295e = identifier;
                    }
                }
            }
        }
        Drawable drawableLoadDrawable = iconCompat.h(context).loadDrawable(context);
        int intrinsicWidth = i7 == 0 ? drawableLoadDrawable.getIntrinsicWidth() : i7;
        if (i7 == 0) {
            i7 = drawableLoadDrawable.getIntrinsicHeight();
        }
        Bitmap bitmapCreateBitmap = Bitmap.createBitmap(intrinsicWidth, i7, Bitmap.Config.ARGB_8888);
        drawableLoadDrawable.setBounds(0, 0, intrinsicWidth, i7);
        if (i6 != 0) {
            drawableLoadDrawable.mutate().setColorFilter(new PorterDuffColorFilter(i6, PorterDuff.Mode.SRC_IN));
        }
        drawableLoadDrawable.draw(new Canvas(bitmapCreateBitmap));
        return bitmapCreateBitmap;
    }

    public void addCompatExtras(Bundle bundle) {
        if (this.mSummaryTextSet) {
            bundle.putCharSequence("android.summaryText", this.mSummaryText);
        }
        CharSequence charSequence = this.mBigContentTitle;
        if (charSequence != null) {
            bundle.putCharSequence("android.title.big", charSequence);
        }
        String className = getClassName();
        if (className != null) {
            bundle.putString("androidx.core.app.extra.COMPAT_TEMPLATE", className);
        }
    }

    public abstract void apply(InterfaceC1001h interfaceC1001h);

    public RemoteViews applyStandardTemplate(boolean z6, int i6, boolean z7) {
        boolean z8;
        int i7;
        Resources resources = this.mBuilder.f11249a.getResources();
        RemoteViews remoteViews = new RemoteViews(this.mBuilder.f11249a.getPackageName(), i6);
        C1007n c1007n = this.mBuilder;
        int i8 = c1007n.f11257i;
        if (c1007n.f11256h != null) {
            remoteViews.setViewVisibility(R.id.icon, 0);
            remoteViews.setImageViewBitmap(R.id.icon, createColoredBitmap(this.mBuilder.f11256h, 0));
            if (z6 && this.mBuilder.f11247B.icon != 0) {
                int dimensionPixelSize = resources.getDimensionPixelSize(R.dimen.notification_right_icon_size);
                int dimensionPixelSize2 = dimensionPixelSize - (resources.getDimensionPixelSize(R.dimen.notification_small_icon_background_padding) * 2);
                C1007n c1007n2 = this.mBuilder;
                remoteViews.setImageViewBitmap(R.id.right_icon, b(c1007n2.f11247B.icon, dimensionPixelSize, dimensionPixelSize2, c1007n2.f11269v));
                remoteViews.setViewVisibility(R.id.right_icon, 0);
            }
        } else if (z6 && c1007n.f11247B.icon != 0) {
            remoteViews.setViewVisibility(R.id.icon, 0);
            int dimensionPixelSize3 = resources.getDimensionPixelSize(R.dimen.notification_large_icon_width) - resources.getDimensionPixelSize(R.dimen.notification_big_circle_margin);
            int dimensionPixelSize4 = resources.getDimensionPixelSize(R.dimen.notification_small_icon_size_as_large);
            C1007n c1007n3 = this.mBuilder;
            remoteViews.setImageViewBitmap(R.id.icon, b(c1007n3.f11247B.icon, dimensionPixelSize3, dimensionPixelSize4, c1007n3.f11269v));
        }
        CharSequence charSequence = this.mBuilder.f11253e;
        if (charSequence != null) {
            remoteViews.setTextViewText(R.id.title, charSequence);
        }
        CharSequence charSequence2 = this.mBuilder.f11254f;
        if (charSequence2 != null) {
            remoteViews.setTextViewText(R.id.text, charSequence2);
            z8 = true;
        } else {
            z8 = false;
        }
        this.mBuilder.getClass();
        this.mBuilder.getClass();
        remoteViews.setViewVisibility(R.id.info, 8);
        CharSequence charSequence3 = this.mBuilder.f11260m;
        if (charSequence3 != null) {
            remoteViews.setTextViewText(R.id.text, charSequence3);
            CharSequence charSequence4 = this.mBuilder.f11254f;
            if (charSequence4 != null) {
                remoteViews.setTextViewText(R.id.text2, charSequence4);
                remoteViews.setViewVisibility(R.id.text2, 0);
                if (z7) {
                    remoteViews.setTextViewTextSize(R.id.text, 0, resources.getDimensionPixelSize(R.dimen.notification_subtext_size));
                }
                remoteViews.setViewPadding(R.id.line1, 0, 0, 0, 0);
            } else {
                remoteViews.setViewVisibility(R.id.text2, 8);
            }
        }
        C1007n c1007n4 = this.mBuilder;
        if ((c1007n4.f11258j ? c1007n4.f11247B.when : 0L) != 0) {
            if (c1007n4.f11259k) {
                remoteViews.setViewVisibility(R.id.chronometer, 0);
                C1007n c1007n5 = this.mBuilder;
                remoteViews.setLong(R.id.chronometer, "setBase", (SystemClock.elapsedRealtime() - System.currentTimeMillis()) + (c1007n5.f11258j ? c1007n5.f11247B.when : 0L));
                remoteViews.setBoolean(R.id.chronometer, "setStarted", true);
                this.mBuilder.getClass();
            } else {
                remoteViews.setViewVisibility(R.id.time, 0);
                C1007n c1007n6 = this.mBuilder;
                remoteViews.setLong(R.id.time, "setTime", c1007n6.f11258j ? c1007n6.f11247B.when : 0L);
            }
            i7 = 0;
        } else {
            i7 = 8;
        }
        remoteViews.setViewVisibility(R.id.right_side, i7);
        remoteViews.setViewVisibility(R.id.line3, z8 ? 0 : 8);
        return remoteViews;
    }

    public final Bitmap b(int i6, int i7, int i8, int i9) {
        if (i9 == 0) {
            i9 = 0;
        }
        Context context = this.mBuilder.f11249a;
        PorterDuff.Mode mode = IconCompat.f11290k;
        context.getClass();
        Bitmap bitmapA = a(IconCompat.d(context.getResources(), context.getPackageName(), R.drawable.notification_icon_background), i9, i7);
        Canvas canvas = new Canvas(bitmapA);
        Drawable drawableMutate = this.mBuilder.f11249a.getResources().getDrawable(i6).mutate();
        drawableMutate.setFilterBitmap(true);
        int i10 = (i7 - i8) / 2;
        int i11 = i8 + i10;
        drawableMutate.setBounds(i10, i10, i11, i11);
        drawableMutate.setColorFilter(new PorterDuffColorFilter(-1, PorterDuff.Mode.SRC_ATOP));
        drawableMutate.draw(canvas);
        return bitmapA;
    }

    public Notification build() {
        C1007n c1007n = this.mBuilder;
        if (c1007n != null) {
            return c1007n.a();
        }
        return null;
    }

    public void buildIntoRemoteViews(RemoteViews remoteViews, RemoteViews remoteViews2) {
        remoteViews.setViewVisibility(R.id.title, 8);
        remoteViews.setViewVisibility(R.id.text2, 8);
        remoteViews.setViewVisibility(R.id.text, 8);
        remoteViews.removeAllViews(R.id.notification_main_column);
        remoteViews.addView(R.id.notification_main_column, remoteViews2.clone());
        remoteViews.setViewVisibility(R.id.notification_main_column, 0);
        Resources resources = this.mBuilder.f11249a.getResources();
        int dimensionPixelSize = resources.getDimensionPixelSize(R.dimen.notification_top_pad);
        int dimensionPixelSize2 = resources.getDimensionPixelSize(R.dimen.notification_top_pad_large_text);
        float f6 = resources.getConfiguration().fontScale;
        if (f6 < 1.0f) {
            f6 = 1.0f;
        } else if (f6 > 1.3f) {
            f6 = 1.3f;
        }
        float f7 = (f6 - 1.0f) / 0.29999995f;
        remoteViews.setViewPadding(R.id.notification_main_column_container, 0, Math.round((f7 * dimensionPixelSize2) + ((1.0f - f7) * dimensionPixelSize)), 0, 0);
    }

    public void clearCompatExtraKeys(Bundle bundle) {
        bundle.remove("android.summaryText");
        bundle.remove("android.title.big");
        bundle.remove("androidx.core.app.extra.COMPAT_TEMPLATE");
    }

    public Bitmap createColoredBitmap(IconCompat iconCompat, int i6) {
        return a(iconCompat, i6, 0);
    }

    public boolean displayCustomViewInline() {
        return false;
    }

    public String getClassName() {
        return null;
    }

    public RemoteViews makeBigContentView(InterfaceC1001h interfaceC1001h) {
        return null;
    }

    public RemoteViews makeContentView(InterfaceC1001h interfaceC1001h) {
        return null;
    }

    public RemoteViews makeHeadsUpContentView(InterfaceC1001h interfaceC1001h) {
        return null;
    }

    public void restoreFromCompatExtras(Bundle bundle) {
        if (bundle.containsKey("android.summaryText")) {
            this.mSummaryText = bundle.getCharSequence("android.summaryText");
            this.mSummaryTextSet = true;
        }
        this.mBigContentTitle = bundle.getCharSequence("android.title.big");
    }

    public void setBuilder(C1007n c1007n) {
        if (this.mBuilder != c1007n) {
            this.mBuilder = c1007n;
            if (c1007n != null) {
                c1007n.d(this);
            }
        }
    }

    public Bitmap createColoredBitmap(int i6, int i7) {
        Context context = this.mBuilder.f11249a;
        PorterDuff.Mode mode = IconCompat.f11290k;
        context.getClass();
        return a(IconCompat.d(context.getResources(), context.getPackageName(), i6), i7, 0);
    }
}
