package com.google.android.m4b.maps.bu;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.IBinder;
import android.os.Process;
import android.util.Pair;
import com.google.android.m4b.maps.ak.g;
import com.google.android.m4b.maps.ak.h;
import com.google.android.m4b.maps.ak.j;
import com.google.android.m4b.maps.o.a;
import com.google.android.m4b.maps.o.a.a;
import com.google.android.m4b.maps.z.b;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public final class c
  implements j, Runnable
{
  private final Context a;
  private final String b;
  private final h c;
  private final b d;
  private final ScheduledExecutorService e;
  private Future<?> f;
  private final Random g;
  private int h;
  private volatile a i;
  private long j;
  private boolean k = false;
  private final Runnable l = new Runnable()
  {
    public final void run()
    {
      c.b(c.this);
    }
  };
  private final ServiceConnection m = new ServiceConnection()
  {
    public final void onServiceConnected(ComponentName paramAnonymousComponentName, IBinder paramAnonymousIBinder)
    {
      c.a(c.this, a.a.a(paramAnonymousIBinder));
      c.d(c.this).schedule(c.c(c.this), 0L, TimeUnit.MILLISECONDS);
    }

    public final void onServiceDisconnected(ComponentName paramAnonymousComponentName)
    {
      c.a(c.this, null);
    }
  };

  static
  {
    c.class.getSimpleName();
  }

  @VisibleForTesting
  private c(Context paramContext, String paramString, h paramh, b paramb, Random paramRandom, ScheduledExecutorService paramScheduledExecutorService)
  {
    this.a = paramContext;
    this.b = paramString;
    this.c = paramh;
    this.d = paramb;
    this.g = paramRandom;
    this.e = paramScheduledExecutorService;
  }

  // ERROR //
  private Pair<String, Long> a(FileInputStream paramFileInputStream)
  {
    // Byte code:
    //   0: new 81	java/io/DataInputStream
    //   3: dup
    //   4: aload_1
    //   5: invokespecial 84	java/io/DataInputStream:<init>	(Ljava/io/InputStream;)V
    //   8: astore_2
    //   9: aload_2
    //   10: invokevirtual 88	java/io/DataInputStream:readLong	()J
    //   13: lstore 7
    //   15: aload_2
    //   16: invokevirtual 91	java/io/DataInputStream:readUTF	()Ljava/lang/String;
    //   19: astore 9
    //   21: aload_2
    //   22: invokevirtual 91	java/io/DataInputStream:readUTF	()Ljava/lang/String;
    //   25: astore 13
    //   27: aload_0
    //   28: getfield 66	com/google/android/m4b/maps/bu/c:b	Ljava/lang/String;
    //   31: aload 13
    //   33: invokevirtual 97	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   36: istore 14
    //   38: iload 14
    //   40: ifne +11 -> 51
    //   43: aload_2
    //   44: invokevirtual 100	java/io/DataInputStream:close	()V
    //   47: aconst_null
    //   48: areturn
    //   49: astore 10
    //   51: aload 9
    //   53: lload 7
    //   55: invokestatic 106	java/lang/Long:valueOf	(J)Ljava/lang/Long;
    //   58: invokestatic 112	android/util/Pair:create	(Ljava/lang/Object;Ljava/lang/Object;)Landroid/util/Pair;
    //   61: astore 11
    //   63: aload_2
    //   64: invokevirtual 100	java/io/DataInputStream:close	()V
    //   67: aload 11
    //   69: areturn
    //   70: astore 12
    //   72: aload 11
    //   74: areturn
    //   75: astore 5
    //   77: aload_2
    //   78: invokevirtual 100	java/io/DataInputStream:close	()V
    //   81: aconst_null
    //   82: areturn
    //   83: astore 6
    //   85: aconst_null
    //   86: areturn
    //   87: astore_3
    //   88: aload_2
    //   89: invokevirtual 100	java/io/DataInputStream:close	()V
    //   92: aload_3
    //   93: athrow
    //   94: astore 15
    //   96: aconst_null
    //   97: areturn
    //   98: astore 4
    //   100: goto -8 -> 92
    //
    // Exception table:
    //   from	to	target	type
    //   21	38	49	java/io/EOFException
    //   63	67	70	java/io/IOException
    //   9	21	75	java/io/IOException
    //   21	38	75	java/io/IOException
    //   51	63	75	java/io/IOException
    //   77	81	83	java/io/IOException
    //   9	21	87	finally
    //   21	38	87	finally
    //   51	63	87	finally
    //   43	47	94	java/io/IOException
    //   88	92	98	java/io/IOException
  }

  public static c a(Context paramContext, String paramString, h paramh)
  {
    return new c(paramContext, paramString, paramh, new b(), new Random(), Executors.newSingleThreadScheduledExecutor());
  }

  private void a(long paramLong)
  {
    if (this.f != null)
      this.f.cancel(true);
    if (paramLong == 0L)
    {
      this.f = null;
      run();
      return;
    }
    this.f = this.e.schedule(this, paramLong, TimeUnit.MILLISECONDS);
  }

  // ERROR //
  private void a(String paramString, long paramLong)
  {
    // Byte code:
    //   0: aload_1
    //   1: ifnonnull +16 -> 17
    //   4: aload_0
    //   5: getfield 64	com/google/android/m4b/maps/bu/c:a	Landroid/content/Context;
    //   8: ldc 161
    //   10: invokevirtual 167	android/content/Context:deleteFile	(Ljava/lang/String;)Z
    //   13: ifeq +3 -> 16
    //   16: return
    //   17: aload_0
    //   18: getfield 64	com/google/android/m4b/maps/bu/c:a	Landroid/content/Context;
    //   21: ldc 161
    //   23: iconst_0
    //   24: invokevirtual 171	android/content/Context:openFileOutput	(Ljava/lang/String;I)Ljava/io/FileOutputStream;
    //   27: astore 5
    //   29: new 173	java/io/DataOutputStream
    //   32: dup
    //   33: aload 5
    //   35: invokespecial 176	java/io/DataOutputStream:<init>	(Ljava/io/OutputStream;)V
    //   38: astore 6
    //   40: aload 6
    //   42: lload_2
    //   43: invokevirtual 179	java/io/DataOutputStream:writeLong	(J)V
    //   46: aload 6
    //   48: aload_1
    //   49: invokevirtual 183	java/io/DataOutputStream:writeUTF	(Ljava/lang/String;)V
    //   52: aload 6
    //   54: aload_0
    //   55: getfield 66	com/google/android/m4b/maps/bu/c:b	Ljava/lang/String;
    //   58: invokevirtual 183	java/io/DataOutputStream:writeUTF	(Ljava/lang/String;)V
    //   61: aload 6
    //   63: invokevirtual 184	java/io/DataOutputStream:close	()V
    //   66: return
    //   67: astore 11
    //   69: return
    //   70: astore 9
    //   72: aload 6
    //   74: invokevirtual 184	java/io/DataOutputStream:close	()V
    //   77: return
    //   78: astore 10
    //   80: return
    //   81: astore 7
    //   83: aload 6
    //   85: invokevirtual 184	java/io/DataOutputStream:close	()V
    //   88: aload 7
    //   90: athrow
    //   91: astore 8
    //   93: goto -5 -> 88
    //   96: astore 4
    //   98: return
    //
    // Exception table:
    //   from	to	target	type
    //   61	66	67	java/io/IOException
    //   40	61	70	java/io/IOException
    //   72	77	78	java/io/IOException
    //   40	61	81	finally
    //   83	88	91	java/io/IOException
    //   17	29	96	java/io/FileNotFoundException
  }

  public static boolean a(Context paramContext)
  {
    if (paramContext.checkPermission("android.permission.ACCESS_NETWORK_STATE", Process.myPid(), Process.myUid()) == 0)
    {
      NetworkInfo localNetworkInfo = ((ConnectivityManager)paramContext.getSystemService("connectivity")).getActiveNetworkInfo();
      return (localNetworkInfo != null) && (localNetworkInfo.isConnected());
    }
    return true;
  }

  private void b(String paramString, long paramLong)
  {
    try
    {
      this.c.f(paramString);
      this.c.a(this);
      this.c.e();
      this.c.e();
      this.h = 0;
      long l1 = paramLong - 300000L;
      if (l1 > 0L)
        a(l1);
      return;
    }
    finally
    {
    }
  }

  private void d()
  {
    if (this.k)
      return;
    bx.a(6, "Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.");
    String str1 = this.b;
    String str2 = this.a.getPackageName();
    String str3 = com.google.android.m4b.maps.ao.c.a(this.a.getPackageManager(), str2);
    if (str3 == null);
    for (String str4 = null; ; str4 = Joiner.on(":").join(Splitter.fixedLength(2).split(str3.toUpperCase())))
    {
      bx.a(6, "In the Google Developer Console (https://console.developers.google.com)\nEnsure that the \"Google Maps Android API v2\" is enabled.\nEnsure that the following Android Key exists:\n\tAPI Key: " + str1 + "\n\tAndroid Application (<cert_fingerprint>;<package_name>): " + str4 + ";" + str2);
      this.k = true;
      return;
    }
  }

  private Pair<String, Long> e()
  {
    try
    {
      FileInputStream localFileInputStream = this.a.openFileInput("_m_t");
      return a(localFileInputStream);
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
    }
    return null;
  }

  private void f()
  {
    Intent localIntent = new Intent();
    localIntent.setClassName("com.google.android.gms", "com.google.android.gms.maps.auth.ApiTokenService");
    if (!this.a.bindService(localIntent, this.m, 1))
      g();
  }

  private void g()
  {
    if (this.f != null)
      this.f.cancel(true);
  }

  public final void a()
  {
    try
    {
      long l1 = this.d.a();
      long l2 = this.j;
      if (l1 < l2 + 60000L);
      while (true)
      {
        return;
        if (!this.c.c())
        {
          this.j = l1;
          this.c.d();
          this.c.d();
          a(null, -1L);
          a(0L);
        }
      }
    }
    finally
    {
    }
  }

  public final void a(int paramInt, boolean paramBoolean, String paramString)
  {
  }

  public final void a(g paramg)
  {
  }

  public final void b()
  {
    try
    {
      d();
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public final void b(g paramg)
  {
  }

  public final void c()
  {
    while (true)
    {
      String str;
      long l1;
      try
      {
        Pair localPair = e();
        if (localPair == null)
        {
          a(0L);
          return;
        }
        str = (String)localPair.first;
        l1 = ((Long)localPair.second).longValue() - this.d.a();
        if (l1 <= 300000L)
        {
          a(0L);
          continue;
        }
      }
      finally
      {
      }
      b(str, l1);
    }
  }

  public final void run()
  {
    try
    {
      if (a(this.a))
        f();
      while (true)
      {
        return;
        new a().a(this.a);
      }
    }
    finally
    {
    }
  }

  final class a extends BroadcastReceiver
  {
    private volatile boolean a;

    a()
    {
    }

    public final void a(Context paramContext)
    {
      this.a = true;
      paramContext.registerReceiver(this, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
    }

    public final void onReceive(Context paramContext, Intent paramIntent)
    {
      if ((c.a(paramContext)) && (this.a))
      {
        c.a(c.this);
        paramContext.unregisterReceiver(this);
        this.a = false;
      }
    }
  }
}

/* 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.bu.c
 * JD-Core Version:    0.6.2
 */