zzm.java 8.53 KB
package com.google.android.gms.common.internal;

import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;

public final class zzm
  implements Handler.Callback
{
  final ArrayList<GoogleApiClient.ConnectionCallbacks> a = new ArrayList();
  private final zza b;
  private final ArrayList<GoogleApiClient.ConnectionCallbacks> c = new ArrayList();
  private final ArrayList<GoogleApiClient.OnConnectionFailedListener> d = new ArrayList();
  private volatile boolean e = false;
  private final AtomicInteger f = new AtomicInteger(0);
  private boolean g = false;
  private final Handler h;
  private final Object i = new Object();
  
  public zzm(Looper paramLooper, zza paramzza)
  {
    this.b = paramzza;
    this.h = new Handler(paramLooper, this);
  }
  
  public final boolean handleMessage(Message arg1)
  {
    if (???.what == 1)
    {
      GoogleApiClient.ConnectionCallbacks localConnectionCallbacks = (GoogleApiClient.ConnectionCallbacks)???.obj;
      synchronized (this.i)
      {
        if ((this.e) && (this.b.isConnected()) && (this.c.contains(localConnectionCallbacks))) {
          localConnectionCallbacks.onConnected(this.b.zzuC());
        }
        return true;
      }
    }
    int j = ???.what;
    Log.wtf("GmsClientEvents", 45 + "Don't know how to handle message: " + j, new Exception());
    return false;
  }
  
  public final boolean isConnectionCallbacksRegistered(GoogleApiClient.ConnectionCallbacks paramConnectionCallbacks)
  {
    zzac.zzw(paramConnectionCallbacks);
    synchronized (this.i)
    {
      boolean bool = this.c.contains(paramConnectionCallbacks);
      return bool;
    }
  }
  
  public final boolean isConnectionFailedListenerRegistered(GoogleApiClient.OnConnectionFailedListener paramOnConnectionFailedListener)
  {
    zzac.zzw(paramOnConnectionFailedListener);
    synchronized (this.i)
    {
      boolean bool = this.d.contains(paramOnConnectionFailedListener);
      return bool;
    }
  }
  
  public final void registerConnectionCallbacks(GoogleApiClient.ConnectionCallbacks paramConnectionCallbacks)
  {
    zzac.zzw(paramConnectionCallbacks);
    synchronized (this.i)
    {
      if (this.c.contains(paramConnectionCallbacks))
      {
        String str = String.valueOf(paramConnectionCallbacks);
        Log.w("GmsClientEvents", String.valueOf(str).length() + 62 + "registerConnectionCallbacks(): listener " + str + " is already registered");
        if (this.b.isConnected()) {
          this.h.sendMessage(this.h.obtainMessage(1, paramConnectionCallbacks));
        }
        return;
      }
      this.c.add(paramConnectionCallbacks);
    }
  }
  
  public final void registerConnectionFailedListener(GoogleApiClient.OnConnectionFailedListener paramOnConnectionFailedListener)
  {
    zzac.zzw(paramOnConnectionFailedListener);
    synchronized (this.i)
    {
      if (this.d.contains(paramOnConnectionFailedListener))
      {
        paramOnConnectionFailedListener = String.valueOf(paramOnConnectionFailedListener);
        Log.w("GmsClientEvents", String.valueOf(paramOnConnectionFailedListener).length() + 67 + "registerConnectionFailedListener(): listener " + paramOnConnectionFailedListener + " is already registered");
        return;
      }
      this.d.add(paramOnConnectionFailedListener);
    }
  }
  
  public final void unregisterConnectionCallbacks(GoogleApiClient.ConnectionCallbacks paramConnectionCallbacks)
  {
    zzac.zzw(paramConnectionCallbacks);
    synchronized (this.i)
    {
      if (!this.c.remove(paramConnectionCallbacks))
      {
        paramConnectionCallbacks = String.valueOf(paramConnectionCallbacks);
        Log.w("GmsClientEvents", String.valueOf(paramConnectionCallbacks).length() + 52 + "unregisterConnectionCallbacks(): listener " + paramConnectionCallbacks + " not found");
      }
      while (!this.g) {
        return;
      }
      this.a.add(paramConnectionCallbacks);
    }
  }
  
  public final void unregisterConnectionFailedListener(GoogleApiClient.OnConnectionFailedListener paramOnConnectionFailedListener)
  {
    zzac.zzw(paramOnConnectionFailedListener);
    synchronized (this.i)
    {
      if (!this.d.remove(paramOnConnectionFailedListener))
      {
        paramOnConnectionFailedListener = String.valueOf(paramOnConnectionFailedListener);
        Log.w("GmsClientEvents", String.valueOf(paramOnConnectionFailedListener).length() + 57 + "unregisterConnectionFailedListener(): listener " + paramOnConnectionFailedListener + " not found");
      }
      return;
    }
  }
  
  public final void zzcV(int paramInt)
  {
    boolean bool = false;
    if (Looper.myLooper() == this.h.getLooper()) {
      bool = true;
    }
    zzac.zza(bool, "onUnintentionalDisconnection must only be called on the Handler thread");
    this.h.removeMessages(1);
    synchronized (this.i)
    {
      this.g = true;
      Object localObject2 = new ArrayList(this.c);
      int j = this.f.get();
      localObject2 = ((ArrayList)localObject2).iterator();
      while (((Iterator)localObject2).hasNext())
      {
        GoogleApiClient.ConnectionCallbacks localConnectionCallbacks = (GoogleApiClient.ConnectionCallbacks)((Iterator)localObject2).next();
        if ((this.e) && (this.f.get() == j)) {
          if (this.c.contains(localConnectionCallbacks)) {
            localConnectionCallbacks.onConnectionSuspended(paramInt);
          }
        }
      }
    }
    this.a.clear();
    this.g = false;
  }
  
  public final void zzn(ConnectionResult paramConnectionResult)
  {
    if (Looper.myLooper() == this.h.getLooper()) {}
    for (boolean bool = true;; bool = false)
    {
      zzac.zza(bool, "onConnectionFailure must only be called on the Handler thread");
      this.h.removeMessages(1);
      synchronized (this.i)
      {
        Object localObject2 = new ArrayList(this.d);
        int j = this.f.get();
        localObject2 = ((ArrayList)localObject2).iterator();
        while (((Iterator)localObject2).hasNext())
        {
          GoogleApiClient.OnConnectionFailedListener localOnConnectionFailedListener = (GoogleApiClient.OnConnectionFailedListener)((Iterator)localObject2).next();
          if ((!this.e) || (this.f.get() != j)) {
            return;
          }
          if (this.d.contains(localOnConnectionFailedListener)) {
            localOnConnectionFailedListener.onConnectionFailed(paramConnectionResult);
          }
        }
      }
      return;
    }
  }
  
  public final void zzq(Bundle paramBundle)
  {
    boolean bool2 = true;
    boolean bool1;
    if (Looper.myLooper() == this.h.getLooper())
    {
      bool1 = true;
      zzac.zza(bool1, "onConnectionSuccess must only be called on the Handler thread");
    }
    for (;;)
    {
      synchronized (this.i)
      {
        if (this.g) {
          break label190;
        }
        bool1 = true;
        zzac.zzaw(bool1);
        this.h.removeMessages(1);
        this.g = true;
        if (this.a.size() != 0) {
          break label195;
        }
        bool1 = bool2;
        zzac.zzaw(bool1);
        Object localObject2 = new ArrayList(this.c);
        int j = this.f.get();
        localObject2 = ((ArrayList)localObject2).iterator();
        if (!((Iterator)localObject2).hasNext()) {
          break label200;
        }
        GoogleApiClient.ConnectionCallbacks localConnectionCallbacks = (GoogleApiClient.ConnectionCallbacks)((Iterator)localObject2).next();
        if ((!this.e) || (!this.b.isConnected()) || (this.f.get() != j)) {
          break label200;
        }
        if (this.a.contains(localConnectionCallbacks)) {
          continue;
        }
        localConnectionCallbacks.onConnected(paramBundle);
      }
      bool1 = false;
      break;
      label190:
      bool1 = false;
      continue;
      label195:
      bool1 = false;
    }
    label200:
    this.a.clear();
    this.g = false;
  }
  
  public final void zzxX()
  {
    this.e = false;
    this.f.incrementAndGet();
  }
  
  public final void zzxY()
  {
    this.e = true;
  }
  
  public static abstract interface zza
  {
    public abstract boolean isConnected();
    
    public abstract Bundle zzuC();
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/google/android/gms/common/internal/zzm.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */