package android.os;

import android.annotation.SystemApi;
import android.os.HidlSupport;
import g.a.a.a.a;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.IntPredicate;
import java.util.function.Predicate;
import java.util.function.ToIntFunction;
import java.util.stream.IntStream;

/* JADX INFO: loaded from: classes.dex */
@SystemApi
public class HidlSupport {

    public static final class Mutable<E> {
        public E value;

        public Mutable() {
            this.value = null;
        }

        public Mutable(E e2) {
            this.value = e2;
        }
    }

    @SystemApi
    public static boolean deepEquals(Object obj, Object obj2) {
        Class<?> cls;
        Class<?> cls2;
        if (obj == obj2) {
            return true;
        }
        if (obj == null || obj2 == null || (cls = obj.getClass()) != (cls2 = obj2.getClass())) {
            return false;
        }
        if (cls.isArray()) {
            Class<?> componentType = cls.getComponentType();
            if (componentType != cls2.getComponentType()) {
                return false;
            }
            if (componentType.isPrimitive()) {
                return Objects.deepEquals(obj, obj2);
            }
            final Object[] objArr = (Object[]) obj;
            final Object[] objArr2 = (Object[]) obj2;
            return objArr.length == objArr2.length && IntStream.range(0, objArr.length).allMatch(new IntPredicate() { // from class: c.a.a
                @Override // java.util.function.IntPredicate
                public final boolean test(int i2) {
                    return HidlSupport.deepEquals(objArr[i2], objArr2[i2]);
                }
            });
        }
        if (!(obj instanceof List)) {
            throwErrorIfUnsupportedType(obj);
            return obj.equals(obj2);
        }
        List list = (List) obj;
        List list2 = (List) obj2;
        if (list.size() != list2.size()) {
            return false;
        }
        final Iterator it = list.iterator();
        return list2.stream().allMatch(new Predicate() { // from class: c.a.c
            @Override // java.util.function.Predicate
            public final boolean test(Object obj3) {
                return HidlSupport.deepEquals(it.next(), obj3);
            }
        });
    }

    @SystemApi
    public static int deepHashCode(Object obj) {
        if (obj == null) {
            return 0;
        }
        Class<?> cls = obj.getClass();
        if (cls.isArray()) {
            return cls.getComponentType().isPrimitive() ? primitiveArrayHashCode(obj) : Arrays.hashCode(Arrays.stream((Object[]) obj).mapToInt(new ToIntFunction() { // from class: c.a.b
                @Override // java.util.function.ToIntFunction
                public final int applyAsInt(Object obj2) {
                    return HidlSupport.deepHashCode(obj2);
                }
            }).toArray());
        }
        if (obj instanceof List) {
            return Arrays.hashCode(((List) obj).stream().mapToInt(new ToIntFunction() { // from class: c.a.d
                @Override // java.util.function.ToIntFunction
                public final int applyAsInt(Object obj2) {
                    return HidlSupport.deepHashCode(obj2);
                }
            }).toArray());
        }
        throwErrorIfUnsupportedType(obj);
        return obj.hashCode();
    }

    @SystemApi
    public static native int getPidIfSharable();

    @SystemApi
    public static boolean interfacesEqual(IHwInterface iHwInterface, Object obj) {
        if (iHwInterface == obj) {
            return true;
        }
        if (iHwInterface == null || obj == null || !(obj instanceof IHwInterface)) {
            return false;
        }
        return Objects.equals(iHwInterface.asBinder(), ((IHwInterface) obj).asBinder());
    }

    private static int primitiveArrayHashCode(Object obj) {
        Class<?> componentType = obj.getClass().getComponentType();
        if (componentType == Boolean.TYPE) {
            return Arrays.hashCode((boolean[]) obj);
        }
        if (componentType == Byte.TYPE) {
            return Arrays.hashCode((byte[]) obj);
        }
        if (componentType == Character.TYPE) {
            return Arrays.hashCode((char[]) obj);
        }
        if (componentType == Double.TYPE) {
            return Arrays.hashCode((double[]) obj);
        }
        if (componentType == Float.TYPE) {
            return Arrays.hashCode((float[]) obj);
        }
        if (componentType == Integer.TYPE) {
            return Arrays.hashCode((int[]) obj);
        }
        if (componentType == Long.TYPE) {
            return Arrays.hashCode((long[]) obj);
        }
        if (componentType == Short.TYPE) {
            return Arrays.hashCode((short[]) obj);
        }
        throw new UnsupportedOperationException();
    }

    private static void throwErrorIfUnsupportedType(Object obj) {
        if (!(obj instanceof Collection) || (obj instanceof List)) {
            if (obj instanceof Map) {
                throw new UnsupportedOperationException("Cannot check equality on maps");
            }
        } else {
            StringBuilder sbF = a.F("Cannot check equality on collections other than lists: ");
            sbF.append(obj.getClass().getName());
            throw new UnsupportedOperationException(sbF.toString());
        }
    }
}
