package android.support.v4.app;

import android.app.Notification;
import android.os.Bundle;
import android.support.v4.app.v;
import android.util.Log;
import android.util.SparseArray;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/* JADX INFO: compiled from: NotificationCompatJellybean.java */
/* JADX INFO: loaded from: classes.dex */
class x {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final Object f651a = new Object();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static Field f652b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static boolean f653c;

    public static SparseArray<Bundle> a(List<Bundle> list) {
        int size = list.size();
        SparseArray<Bundle> sparseArray = null;
        for (int i = 0; i < size; i++) {
            Bundle bundle = list.get(i);
            if (bundle != null) {
                if (sparseArray == null) {
                    sparseArray = new SparseArray<>();
                }
                sparseArray.put(i, bundle);
            }
        }
        return sparseArray;
    }

    static Bundle b(v.a aVar) {
        Bundle bundle = new Bundle();
        bundle.putInt("icon", aVar.e());
        bundle.putCharSequence("title", aVar.i());
        bundle.putParcelable("actionIntent", aVar.a());
        Bundle bundle2 = aVar.d() != null ? new Bundle(aVar.d()) : new Bundle();
        bundle2.putBoolean("android.support.allowGeneratedReplies", aVar.b());
        bundle.putBundle("extras", bundle2);
        bundle.putParcelableArray("remoteInputs", e(aVar.f()));
        bundle.putBoolean("showsUserInterface", aVar.h());
        bundle.putInt("semanticAction", aVar.g());
        return bundle;
    }

    public static Bundle c(Notification notification) {
        synchronized (f651a) {
            if (f653c) {
                return null;
            }
            try {
                if (f652b == null) {
                    Field declaredField = Notification.class.getDeclaredField("extras");
                    if (!Bundle.class.isAssignableFrom(declaredField.getType())) {
                        Log.e("NotificationCompat", "Notification.extras field is not of type Bundle");
                        f653c = true;
                        return null;
                    }
                    declaredField.setAccessible(true);
                    f652b = declaredField;
                }
                Bundle bundle = (Bundle) f652b.get(notification);
                if (bundle == null) {
                    bundle = new Bundle();
                    f652b.set(notification, bundle);
                }
                return bundle;
            } catch (IllegalAccessException e2) {
                Log.e("NotificationCompat", "Unable to access notification extras", e2);
                f653c = true;
                return null;
            } catch (NoSuchFieldException e3) {
                Log.e("NotificationCompat", "Unable to access notification extras", e3);
                f653c = true;
                return null;
            }
        }
    }

    private static Bundle d(z zVar) {
        Bundle bundle = new Bundle();
        bundle.putString("resultKey", zVar.h());
        bundle.putCharSequence("label", zVar.g());
        bundle.putCharSequenceArray("choices", zVar.e());
        bundle.putBoolean("allowFreeFormInput", zVar.c());
        bundle.putBundle("extras", zVar.f());
        Set<String> setD = zVar.d();
        if (setD != null && !setD.isEmpty()) {
            ArrayList<String> arrayList = new ArrayList<>(setD.size());
            Iterator<String> it = setD.iterator();
            while (it.hasNext()) {
                arrayList.add(it.next());
            }
            bundle.putStringArrayList("allowedDataTypes", arrayList);
        }
        return bundle;
    }

    private static Bundle[] e(z[] zVarArr) {
        if (zVarArr == null) {
            return null;
        }
        Bundle[] bundleArr = new Bundle[zVarArr.length];
        for (int i = 0; i < zVarArr.length; i++) {
            bundleArr[i] = d(zVarArr[i]);
        }
        return bundleArr;
    }

    public static Bundle f(Notification.Builder builder, v.a aVar) {
        builder.addAction(aVar.e(), aVar.i(), aVar.a());
        Bundle bundle = new Bundle(aVar.d());
        if (aVar.f() != null) {
            bundle.putParcelableArray("android.support.remoteInputs", e(aVar.f()));
        }
        if (aVar.c() != null) {
            bundle.putParcelableArray("android.support.dataRemoteInputs", e(aVar.c()));
        }
        bundle.putBoolean("android.support.allowGeneratedReplies", aVar.b());
        return bundle;
    }
}
