package androidx.core.graphics.drawable;

import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.os.Parcel;
import android.os.Parcelable;
import java.nio.charset.Charset;
import o.AbstractC2455sj0;
import o.C2550tj0;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public class IconCompatParcelizer {
    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    public static IconCompat read(AbstractC2455sj0 abstractC2455sj0) {
        IconCompat iconCompat = new IconCompat();
        int i = iconCompat.a;
        if (abstractC2455sj0.e(1)) {
            i = ((C2550tj0) abstractC2455sj0).e.readInt();
        }
        iconCompat.a = i;
        byte[] bArr = iconCompat.c;
        if (abstractC2455sj0.e(2)) {
            Parcel parcel = ((C2550tj0) abstractC2455sj0).e;
            int i2 = parcel.readInt();
            if (i2 < 0) {
                bArr = null;
            } else {
                byte[] bArr2 = new byte[i2];
                parcel.readByteArray(bArr2);
                bArr = bArr2;
            }
        }
        iconCompat.c = bArr;
        iconCompat.d = abstractC2455sj0.f(iconCompat.d, 3);
        int i3 = iconCompat.e;
        if (abstractC2455sj0.e(4)) {
            i3 = ((C2550tj0) abstractC2455sj0).e.readInt();
        }
        iconCompat.e = i3;
        int i4 = iconCompat.f;
        if (abstractC2455sj0.e(5)) {
            i4 = ((C2550tj0) abstractC2455sj0).e.readInt();
        }
        iconCompat.f = i4;
        iconCompat.g = (ColorStateList) abstractC2455sj0.f(iconCompat.g, 6);
        String string = iconCompat.i;
        if (abstractC2455sj0.e(7)) {
            string = ((C2550tj0) abstractC2455sj0).e.readString();
        }
        iconCompat.i = string;
        String string2 = iconCompat.j;
        if (abstractC2455sj0.e(8)) {
            string2 = ((C2550tj0) abstractC2455sj0).e.readString();
        }
        iconCompat.j = string2;
        iconCompat.h = PorterDuff.Mode.valueOf(iconCompat.i);
        switch (iconCompat.a) {
            case -1:
                Parcelable parcelable = iconCompat.d;
                if (parcelable == null) {
                    throw new IllegalArgumentException("Invalid icon");
                }
                iconCompat.b = parcelable;
                return iconCompat;
            case 0:
            default:
                return iconCompat;
            case 1:
            case 5:
                Parcelable parcelable2 = iconCompat.d;
                if (parcelable2 != null) {
                    iconCompat.b = parcelable2;
                    return iconCompat;
                }
                byte[] bArr3 = iconCompat.c;
                iconCompat.b = bArr3;
                iconCompat.a = 3;
                iconCompat.e = 0;
                iconCompat.f = bArr3.length;
                return iconCompat;
            case 2:
            case 4:
            case 6:
                String str = new String(iconCompat.c, Charset.forName("UTF-16"));
                iconCompat.b = str;
                if (iconCompat.a == 2 && iconCompat.j == null) {
                    iconCompat.j = str.split(":", -1)[0];
                }
                return iconCompat;
            case 3:
                iconCompat.b = iconCompat.c;
                return iconCompat;
        }
    }

    public static void write(IconCompat iconCompat, AbstractC2455sj0 abstractC2455sj0) {
        abstractC2455sj0.getClass();
        iconCompat.i = iconCompat.h.name();
        switch (iconCompat.a) {
            case -1:
                iconCompat.d = (Parcelable) iconCompat.b;
                break;
            case 1:
            case 5:
                iconCompat.d = (Parcelable) iconCompat.b;
                break;
            case 2:
                iconCompat.c = ((String) iconCompat.b).getBytes(Charset.forName("UTF-16"));
                break;
            case 3:
                iconCompat.c = (byte[]) iconCompat.b;
                break;
            case 4:
            case 6:
                iconCompat.c = iconCompat.b.toString().getBytes(Charset.forName("UTF-16"));
                break;
        }
        int i = iconCompat.a;
        if (-1 != i) {
            abstractC2455sj0.h(1);
            ((C2550tj0) abstractC2455sj0).e.writeInt(i);
        }
        byte[] bArr = iconCompat.c;
        if (bArr != null) {
            abstractC2455sj0.h(2);
            Parcel parcel = ((C2550tj0) abstractC2455sj0).e;
            parcel.writeInt(bArr.length);
            parcel.writeByteArray(bArr);
        }
        Parcelable parcelable = iconCompat.d;
        if (parcelable != null) {
            abstractC2455sj0.h(3);
            ((C2550tj0) abstractC2455sj0).e.writeParcelable(parcelable, 0);
        }
        int i2 = iconCompat.e;
        if (i2 != 0) {
            abstractC2455sj0.h(4);
            ((C2550tj0) abstractC2455sj0).e.writeInt(i2);
        }
        int i3 = iconCompat.f;
        if (i3 != 0) {
            abstractC2455sj0.h(5);
            ((C2550tj0) abstractC2455sj0).e.writeInt(i3);
        }
        ColorStateList colorStateList = iconCompat.g;
        if (colorStateList != null) {
            abstractC2455sj0.h(6);
            ((C2550tj0) abstractC2455sj0).e.writeParcelable(colorStateList, 0);
        }
        String str = iconCompat.i;
        if (str != null) {
            abstractC2455sj0.h(7);
            ((C2550tj0) abstractC2455sj0).e.writeString(str);
        }
        String str2 = iconCompat.j;
        if (str2 != null) {
            abstractC2455sj0.h(8);
            ((C2550tj0) abstractC2455sj0).e.writeString(str2);
        }
    }
}
