package com.google.android.m4b.maps.be;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.util.Pair;
import com.google.android.m4b.maps.ak.e;
import com.google.android.m4b.maps.ak.i;
import com.google.android.m4b.maps.ak.r;
import com.google.android.m4b.maps.ax.a;
import com.google.android.m4b.maps.ax.a.a;
import com.google.android.m4b.maps.bc.az;
import com.google.android.m4b.maps.bc.ba;
import com.google.android.m4b.maps.bc.bb;
import com.google.android.m4b.maps.bc.bd.a;
import com.google.android.m4b.maps.bc.be;
import com.google.android.m4b.maps.bc.bg;
import com.google.android.m4b.maps.bc.bo;
import com.google.android.m4b.maps.bg.l;
import com.google.android.m4b.maps.bl.ao;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock;

public abstract class b extends com.google.android.m4b.maps.bk.b
  implements com.google.android.m4b.maps.ak.j, f, j
{
  protected k a;
  protected com.google.android.m4b.maps.z.b b = e.e().b();
  protected final bg c;
  private volatile b e;
  private final ReentrantLock f = new ReentrantLock();
  private final i g;
  private Handler h;
  private boolean i;
  private a j;
  private final List<a> k = new LinkedList();
  private final com.google.android.m4b.maps.bk.f<ba, d> l;
  private final Map<ba, d> m = new HashMap();
  private final int n;
  private volatile int o;
  private volatile int p;
  private volatile int q;
  private boolean r = false;
  private com.google.android.m4b.maps.al.c s;
  private final ArrayList<WeakReference<j.a>> t = new ArrayList();
  private volatile boolean u = false;
  private final com.google.android.m4b.maps.bf.d v = new com.google.android.m4b.maps.bf.d()
  {
    public final void a(ba paramAnonymousba, int paramAnonymousInt, az paramAnonymousaz)
    {
      if (paramAnonymousInt == 0)
        b.a(b.this, paramAnonymousaz);
    }
  };

  protected b(i parami, bg parambg, String paramString, l paraml, com.google.android.m4b.maps.bg.c paramc, int paramInt1, boolean paramBoolean, int paramInt2, Locale paramLocale, File paramFile)
  {
    super(paramString);
    this.c = parambg;
    this.a = new k(getName(), paraml, paramc, paramBoolean, paramLocale, paramFile);
    this.n = paramInt1;
    this.g = parami;
    this.j = g();
    a.a(this.j, this);
    this.l = new com.google.android.m4b.maps.bk.f(paramInt2)
    {
    };
  }

  private Pair<Boolean, d> a(d paramd, boolean paramBoolean1, boolean paramBoolean2)
  {
    boolean bool1 = true;
    Object localObject = null;
    ba localba = paramd.a.a(h());
    if (this.a.a != null)
    {
      az localaz2 = this.a.a.c(localba);
      if ((localaz2 != null) && (!localaz2.a(this.b)))
      {
        boolean bool2;
        if (this.a.a.a(localaz2))
        {
          a(paramd, 2, null);
          bool2 = bool1;
        }
        while (true)
        {
          return Pair.create(Boolean.valueOf(bool2), localObject);
          if ((!paramd.c) && (this.s != null))
            this.s.a();
          d locald = a(localaz2, paramd, paramBoolean2);
          if (!paramBoolean2)
          {
            boolean bool3 = paramd.c;
            az localaz3 = null;
            if (bool3);
            while (true)
            {
              a(paramd, 0, localaz3);
              localObject = locald;
              bool2 = bool1;
              break;
              localaz3 = localaz2;
            }
          }
          localObject = locald;
          bool2 = false;
        }
      }
    }
    if (paramBoolean1)
    {
      com.google.android.m4b.maps.bg.c localc = this.a.b();
      if (localc != null)
        if (paramd.c)
        {
          if (localc.b(localba))
          {
            a(paramd, 0, null);
            return Pair.create(Boolean.valueOf(bool1), null);
          }
        }
        else
        {
          az localaz1 = localc.c(localba);
          if ((localaz1 != null) && (!localaz1.a(this.b)))
          {
            if (localc.a(localaz1))
            {
              if ((!paramd.c) && (this.s != null))
                this.s.c();
              a(paramd, localba);
            }
            while (true)
            {
              return Pair.create(Boolean.valueOf(bool1), localObject);
              if ((!paramd.c) && (this.s != null))
                this.s.b();
              if (this.a.a != null)
                this.a.a.a(localba, localaz1);
              localObject = a(localaz1, paramd, paramBoolean2);
              if (!paramBoolean2)
                a(paramd, 0, localaz1);
              else
                bool1 = false;
            }
          }
        }
    }
    if ((!paramd.c) && (this.s != null))
      this.s.c();
    paramd.i = -1;
    return Pair.create(Boolean.valueOf(false), null);
  }

  private d a(az paramaz, d paramd, boolean paramBoolean)
  {
    int i1 = this.a.d();
    int i2 = -1;
    int i3;
    d locald;
    int i4;
    if ((i1 != -1) && (i1 != paramaz.e()))
    {
      i3 = 1;
      locald = null;
      if (i3 != 0)
      {
        locald = new d(this.c, paramd.a.a(this.c), this.v, a.b.b, true, false, i2, true);
        com.google.android.m4b.maps.al.b.a();
        if (com.google.android.m4b.maps.al.b.f())
        {
          i4 = paramaz.d().b();
          if (this.g.l() % 100L == 8L)
            if (i2 == -1)
              break label271;
        }
      }
    }
    label271: for (int i5 = 1; ; i5 = 0)
    {
      r.a(109, "u", r.a(new String[] { "v=" + i5, "d=" + bo.q(), "z=" + i4 }));
      return locald;
      com.google.android.m4b.maps.al.b.a();
      boolean bool1 = com.google.android.m4b.maps.al.b.f();
      i3 = 0;
      if (!bool1)
        break;
      boolean bool2 = paramd.c;
      i3 = 0;
      if (bool2)
        break;
      if (!paramaz.b(this.b))
      {
        i3 = 0;
        if (!paramBoolean)
          break;
      }
      i2 = paramaz.i();
      i3 = 1;
      break;
    }
  }

  private void a(d paramd)
  {
    if (this.e != null)
      this.e.a();
    Message localMessage = this.h.obtainMessage(1, paramd);
    this.h.sendMessage(localMessage);
  }

  private void a(d paramd, ba paramba)
  {
    if (this.a.a != null)
      this.a.a.a_(paramba);
    a(paramd, 2, null);
  }

  private void b(d paramd)
  {
    ba localba1 = paramd.a.a(this.c);
    if (j.d.equals(localba1))
    {
      a(paramd, 3, null);
      return;
    }
    d locald1 = (d)this.m.get(localba1);
    bg localbg = c(paramd);
    if (localbg != null);
    boolean bool4;
    d locald2;
    for (boolean bool1 = true; ; bool1 = false)
    {
      if (!paramd.f)
        break label144;
      Pair localPair2 = a(paramd, true, false);
      bool4 = ((Boolean)localPair2.first).booleanValue();
      locald2 = (d)localPair2.second;
      label102: if (!bool4)
        a(paramd, 3, null);
      if (locald2 == null)
        break;
      if (locald1 == null)
        break label241;
      if (locald2.g)
        break;
      locald1.a(locald2);
      return;
    }
    label144: boolean bool2 = paramd.e;
    boolean bool3 = false;
    if (bool2);
    while (true)
    {
      bool4 = bool3;
      locald2 = paramd;
      break label102;
      if (locald1 != null)
      {
        boolean bool5 = locald1.a();
        bool3 = false;
        if (!bool5)
        {
          boolean bool6 = locald1.g;
          bool3 = false;
          if (!bool6);
        }
      }
      else
      {
        Pair localPair1 = a(paramd, true, bool1);
        bool4 = ((Boolean)localPair1.first).booleanValue();
        if (bool4)
        {
          locald2 = (d)localPair1.second;
          break label102;
          label241: if ((this.r) && (!this.m.isEmpty()) && (!locald2.c))
          {
            d locald4 = (d)this.l.b(localba1);
            if (locald4 != null)
            {
              locald4.a(locald2);
              return;
            }
            this.l.c(localba1, locald2);
            return;
          }
          this.m.put(localba1, locald2);
          if ((!this.j.a(locald2)) || ((bool1) && (!a.a(this.j, 2))))
            j();
          this.j.a(com.google.android.m4b.maps.al.d.a(h(), localba1), locald2);
          if (bool1)
          {
            ba localba2 = paramd.a.a(localbg);
            d locald3 = new d(localbg, localba2, locald2.b, locald2.d, locald2.e, locald2.f, locald2.i, locald2.g);
            this.j.a(com.google.android.m4b.maps.al.d.a(locald3.h, localba2), locald3);
          }
          this.o = (1 + this.o);
          if ((this.j.l()) || (locald2.e))
          {
            j();
            return;
          }
          if (this.i)
            break;
          Message localMessage = this.h.obtainMessage(2);
          this.h.sendMessageDelayed(localMessage, 50L);
          this.i = true;
          return;
        }
        bool3 = bool4;
      }
    }
  }

  private static bg c(d paramd)
  {
    Iterator localIterator = paramd.a.j().a().iterator();
    while (localIterator.hasNext())
    {
      bd.a locala = (bd.a)localIterator.next();
      if (locala.a() != null)
        return locala.a();
    }
    return null;
  }

  private void i()
  {
    ArrayList localArrayList1 = this.t;
    int i2;
    for (int i1 = 0; ; i1 = i2 + 1)
    {
      try
      {
        if (i1 < this.t.size())
        {
          j.a locala = (j.a)((WeakReference)this.t.get(i1)).get();
          if (locala != null)
          {
            locala.a();
            i2 = i1;
          }
          else
          {
            ArrayList localArrayList2 = this.t;
            i2 = i1 - 1;
            localArrayList2.remove(i1);
          }
        }
      }
      finally
      {
      }
      return;
    }
  }

  private void j()
  {
    if (this.j.k() > 0)
    {
      a.b(new a.a("addRequest", this.j));
      this.g.c(this.j);
      this.k.add(this.j);
      this.j = g();
      a.a(this.j, this);
    }
  }

  private void k()
  {
    try
    {
      this.f.lock();
      if ((this.a.b != null) && (this.a.b.b()) && ((this.e == null) || (this.e.b())))
        this.e = new b();
      return;
    }
    finally
    {
      this.f.unlock();
    }
  }

  public az a(ba paramba, boolean paramBoolean)
  {
    c localc = new c();
    d locald = (d)a(new d(this.c, paramba, localc), paramBoolean, false).second;
    if (locald != null)
      this.h.sendMessage(this.h.obtainMessage(1, locald));
    return c.a(localc);
  }

  public final void a()
  {
  }

  public final void a(int paramInt, boolean paramBoolean, String paramString)
  {
    String str1 = getName();
    StringBuilder localStringBuilder = new StringBuilder("Network Error! ").append(paramInt).append(" : ").append(paramBoolean);
    if (paramString != null);
    for (String str2 = " : " + paramString; ; str2 = "")
    {
      com.google.android.m4b.maps.al.d.a(str1, str2);
      this.h.sendMessage(this.h.obtainMessage(4));
      return;
    }
  }

  public final void a(com.google.android.m4b.maps.ak.g paramg)
  {
    if (((paramg instanceof a)) && (a.a((a)paramg) == this))
      this.h.sendMessage(this.h.obtainMessage(3, paramg));
  }

  public final void a(com.google.android.m4b.maps.al.c paramc)
  {
    this.s = paramc;
  }

  public void a(ba paramba, com.google.android.m4b.maps.bf.d paramd)
  {
    a(new d(this.c, paramba, paramd));
  }

  @VisibleForTesting
  final void a(d paramd, int paramInt, az paramaz)
  {
    int i1 = 0;
    d locald = paramd;
    if (locald != null)
    {
      if ((paramInt == 0) && (g.a(locald.d)))
        if (paramaz.j())
        {
          this.a.b().a(paramd.a, locald.b, g.a(locald.d, true));
          i1 = 1;
        }
      while (true)
      {
        locald = d.b(locald);
        break;
        d.a(locald, 4, paramaz);
        continue;
        d.a(locald, paramInt, paramaz);
      }
    }
    if (i1 != 0)
    {
      this.u = true;
      k();
    }
  }

  public final void a(j.a parama)
  {
    synchronized (this.t)
    {
      this.t.add(new WeakReference(parama));
      return;
    }
  }

  public final void b()
  {
  }

  public final void b(com.google.android.m4b.maps.ak.g paramg)
  {
  }

  public final void b(ba paramba, com.google.android.m4b.maps.bf.d paramd)
  {
    a(new d(this.c, paramba, paramd, true, false));
  }

  public final void c()
  {
    this.a.c();
    i();
  }

  public final void d()
  {
    this.g.a(this);
    start();
    try
    {
      try
      {
        while (this.h == null)
          wait();
      }
      finally
      {
      }
    }
    catch (InterruptedException localInterruptedException)
    {
      Thread.currentThread().interrupt();
      return;
    }
  }

  public final void e()
  {
    k localk = this.a;
    if (localk.a != null)
      localk.a.a();
  }

  public void f()
  {
    try
    {
      Process.setThreadPriority(ao.d());
      Looper.prepare();
      Looper.myLooper();
      this.h = new Handler()
      {
        public final void handleMessage(Message paramAnonymousMessage)
        {
          switch (paramAnonymousMessage.what)
          {
          default:
            return;
          case 1:
            b.a(b.this, (b.d)paramAnonymousMessage.obj);
            return;
          case 2:
            b.a(b.this);
            return;
          case 3:
            b.a(b.this, (b.a)paramAnonymousMessage.obj);
            return;
          case 4:
            b.b(b.this);
            return;
          case 5:
            synchronized (paramAnonymousMessage.obj)
            {
              paramAnonymousMessage.obj.notify();
              b.c(b.this);
              return;
            }
          case 6:
          }
          Pair localPair = (Pair)paramAnonymousMessage.obj;
          b.a(b.this, (bb)((Pair)localPair.first).first, (a.b)((Pair)localPair.first).second, (com.google.android.m4b.maps.bf.d)localPair.second);
        }
      };
    }
    catch (SecurityException localSecurityException)
    {
      try
      {
        notifyAll();
        this.a.a();
        return;
        localSecurityException = localSecurityException;
        com.google.android.m4b.maps.al.d.a(getName(), "Could not set thread priority: " + localSecurityException);
      }
      finally
      {
      }
    }
  }

  protected abstract a g();

  public bg h()
  {
    return this.c;
  }

  public static abstract class a extends com.google.android.m4b.maps.ak.b
  {
    private final b.d[] a = new b.d[8];
    private int b = 0;
    private b c;
    private final Map<Pair<Long, String>, Integer> d = Maps.newHashMap();

    protected a(int paramInt)
    {
    }

    @VisibleForTesting
    public final b.d a(int paramInt)
    {
      return this.a[paramInt];
    }

    @VisibleForTesting
    public final Integer a(Pair<Long, String> paramPair)
    {
      if (paramPair.second == null)
        paramPair = new Pair(paramPair.first, "");
      return (Integer)this.d.get(paramPair);
    }

    protected final void a(Pair<Long, String> paramPair, b.d paramd)
    {
      if (paramPair.second == null)
        paramPair = new Pair(paramPair.first, "");
      if (this.d.get(paramPair) != null)
        throw new IllegalArgumentException("Duplicate tile key: " + paramPair + ", already exists in batch for " + paramd);
      this.d.put(paramPair, Integer.valueOf(this.b));
      b.d[] arrayOfd = this.a;
      int i = this.b;
      this.b = (i + 1);
      arrayOfd[i] = paramd;
    }

    protected boolean a(b.d paramd)
    {
      return true;
    }

    protected abstract az b(int paramInt);

    protected byte[] c(int paramInt)
    {
      return null;
    }

    protected int j()
    {
      return -1;
    }

    @VisibleForTesting
    public final int k()
    {
      return this.b;
    }

    protected final boolean l()
    {
      return this.b == this.a.length;
    }
  }

  final class b extends com.google.android.m4b.maps.bk.b
  {
    private volatile boolean a;
    private volatile boolean b;

    b()
    {
      super();
      if (b.d(b.this) < 0)
      {
        this.b = true;
        return;
      }
      start();
    }

    final void a()
    {
      this.a = true;
    }

    final boolean b()
    {
      return this.b;
    }

    public final void f()
    {
      try
      {
        Process.setThreadPriority(1 + ao.d());
        localc = b.this.a.b();
        if (localc == null)
          return;
      }
      catch (SecurityException localSecurityException)
      {
        com.google.android.m4b.maps.bg.c localc;
        while (true)
          com.google.android.m4b.maps.al.d.a(getName(), "Could not set thread priority: " + localSecurityException);
        if ((!this.a) && (b.e(b.this)))
        {
          b.a(b.this, false);
          localc.d_();
        }
        while (true)
        {
          this.b = true;
          b.f(b.this);
          return;
          label96: this.a = false;
          try
          {
            for (int i = b.d(b.this); i > 0; i -= 1000)
            {
              sleep(1000L);
              if (b.e(b.this))
                break;
            }
            if (this.a)
              break label96;
            b.a(b.this, false);
            localc.d_();
          }
          catch (InterruptedException localInterruptedException)
          {
          }
        }
      }
    }
  }

  public static final class c
    implements com.google.android.m4b.maps.bf.d
  {
    private az a;

    public final void a(ba paramba, int paramInt, az paramaz)
    {
      if (paramInt == 0)
        this.a = paramaz;
    }
  }

  public static final class d
  {
    final ba a;
    final com.google.android.m4b.maps.bf.d b;
    final boolean c;
    final a.b d;
    final boolean e;
    final boolean f;
    final boolean g;
    final bg h;
    int i;
    private volatile boolean j = false;
    private d k = null;

    protected d(bg parambg, ba paramba, com.google.android.m4b.maps.bf.d paramd)
    {
      this(parambg, paramba, paramd, a.b.b, false, false, -1, false);
    }

    protected d(bg parambg, ba paramba, com.google.android.m4b.maps.bf.d paramd, a.b paramb, boolean paramBoolean1, boolean paramBoolean2, int paramInt, boolean paramBoolean3)
    {
      this.h = parambg;
      this.a = paramba;
      this.b = paramd;
      this.d = paramb;
      boolean bool1;
      if (!paramb.equals(a.b.e))
      {
        boolean bool2 = paramb.equals(a.b.d);
        bool1 = false;
        if (!bool2);
      }
      else
      {
        bool1 = true;
      }
      this.c = bool1;
      this.e = paramBoolean1;
      this.i = paramInt;
      this.f = paramBoolean2;
      this.g = paramBoolean3;
    }

    protected d(bg parambg, ba paramba, com.google.android.m4b.maps.bf.d paramd, boolean paramBoolean1, boolean paramBoolean2)
    {
      this(parambg, paramba, paramd, a.b.b, false, true, -1, false);
    }

    @VisibleForTesting
    final void a(d paramd)
    {
      paramd.k = this.k;
      this.k = paramd;
    }

    protected final boolean a()
    {
      return this.k != null;
    }

    public final String toString()
    {
      return this.h + "/" + this.a;
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.google.android.m4b.maps.be.b
 * JD-Core Version:    0.6.2
 */