package a.b.a.k.f;

import android.net.wifi.p2p.WifiP2pGroup;
import android.net.wifi.p2p.WifiP2pManager;
import android.text.TextUtils;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collection;

public class c {

    /* renamed from: a  reason: collision with root package name */
    private static final String f50a = "WifiP2pManagerProxy";

    public class a implements InvocationHandler {

        /* renamed from: a  reason: collision with root package name */
        public final /* synthetic */ Method f51a;
        public final /* synthetic */ AbstractC0004c b;

        public a(Method method, AbstractC0004c cVar) {
            this.f51a = method;
            this.b = cVar;
        }

        @Override // java.lang.reflect.InvocationHandler
        public Object invoke(Object obj, Method method, Object[] objArr) throws Throwable {
            if (!TextUtils.equals("onPersistentGroupInfoAvailable", method.getName())) {
                return null;
            }
            Collection<WifiP2pGroup> collection = (Collection) this.f51a.invoke(objArr[0], new Object[0]);
            AbstractC0004c cVar = this.b;
            if (cVar == null) {
                return null;
            }
            cVar.a(collection);
            return null;
        }
    }

    public class b implements AbstractC0004c {

        /* renamed from: a  reason: collision with root package name */
        public final /* synthetic */ Method f52a;
        public final /* synthetic */ WifiP2pManager b;
        public final /* synthetic */ WifiP2pManager.Channel c;

        public b(Method method, WifiP2pManager wifiP2pManager, WifiP2pManager.Channel channel) {
            this.f52a = method;
            this.b = wifiP2pManager;
            this.c = channel;
        }

        @Override // a.b.a.k.f.c.AbstractC0004c
        public void a(Collection<WifiP2pGroup> collection) {
            for (WifiP2pGroup wifiP2pGroup : collection) {
                int i = 0;
                try {
                    i = ((Integer) this.f52a.invoke(wifiP2pGroup, new Object[0])).intValue();
                } catch (IllegalAccessException | InvocationTargetException e) {
                    a.a.a.b.b(c.f50a, "getNetworkId exception ", e);
                }
                c.a(this.b, this.c, i, new a.b.a.k.b(c.f50a, "Delete " + i));
            }
        }
    }

    /* renamed from: a.b.a.k.f.c$c  reason: collision with other inner class name */
    public interface AbstractC0004c {
        void a(Collection<WifiP2pGroup> collection);
    }

    public static void a(WifiP2pManager wifiP2pManager, WifiP2pManager.Channel channel) {
        a.a.a.b.a(f50a, "Delete all persistent groups.");
        a(wifiP2pManager, channel, new b(WifiP2pGroup.class.getDeclaredMethod("getNetworkId", new Class[0]), wifiP2pManager, channel));
    }

    public static void a(WifiP2pManager wifiP2pManager, WifiP2pManager.Channel channel, int i, WifiP2pManager.ActionListener actionListener) {
        a.a.a.b.a(f50a, "Delete persistent group.");
        WifiP2pManager.class.getDeclaredMethod("deletePersistentGroup", WifiP2pManager.Channel.class, Integer.TYPE, WifiP2pManager.ActionListener.class).invoke(wifiP2pManager, channel, Integer.valueOf(i), actionListener);
    }

    public static boolean a(WifiP2pManager wifiP2pManager, WifiP2pManager.Channel channel, AbstractC0004c cVar) {
        try {
            a aVar = new a(Class.forName("android.net.wifi.p2p.WifiP2pGroupList").getDeclaredMethod("getGroupList", new Class[0]), cVar);
            Class<?> cls = Class.forName("android.net.wifi.p2p.WifiP2pManager$PersistentGroupInfoListener");
            Method declaredMethod = WifiP2pManager.class.getDeclaredMethod("requestPersistentGroupInfo", WifiP2pManager.Channel.class, cls);
            ClassLoader classLoader = cls.getClassLoader();
            if (classLoader != null) {
                declaredMethod.invoke(wifiP2pManager, channel, Proxy.newProxyInstance(classLoader, new Class[]{cls}, aVar));
            }
            return true;
        } catch (Exception e) {
            a.a.a.b.e(f50a, "Request persistent group info failed.", e);
            return false;
        }
    }

    public static boolean b(WifiP2pManager wifiP2pManager, WifiP2pManager.Channel channel, int i, WifiP2pManager.ActionListener actionListener) {
        a.a.a.b.a(f50a, "Try to set channel to " + i);
        Class cls = Integer.TYPE;
        WifiP2pManager.class.getDeclaredMethod("setWifiP2pChannels", WifiP2pManager.Channel.class, cls, cls, WifiP2pManager.ActionListener.class).invoke(wifiP2pManager, channel, 0, Integer.valueOf(i), actionListener);
        return true;
    }
}
