zzb.java 6.66 KB
package com.google.firebase.iid;

import android.app.Service;
import android.content.BroadcastReceiver.PendingResult;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.IBinder;
import android.os.Process;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;
import android.util.Pair;
import com.google.android.gms.common.stats.zza;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public abstract class zzb
  extends Service
{
  private Binder a;
  private final Object b = new Object();
  @VisibleForTesting
  final ExecutorService c = Executors.newSingleThreadExecutor();
  private int d;
  private int e = 0;
  
  private void a(Intent arg1)
  {
    if (??? != null) {
      WakefulBroadcastReceiver.completeWakefulIntent(???);
    }
    synchronized (this.b)
    {
      this.e -= 1;
      if (this.e == 0) {
        stopSelfResult(this.d);
      }
      return;
    }
  }
  
  public abstract void handleIntent(Intent paramIntent);
  
  public final IBinder onBind(Intent paramIntent)
  {
    try
    {
      Log.isLoggable("EnhancedIntentService", 3);
      if (this.a == null) {
        this.a = new zza(this);
      }
      paramIntent = this.a;
      return paramIntent;
    }
    finally {}
  }
  
  public final int onStartCommand(final Intent paramIntent, int paramInt1, int paramInt2)
  {
    synchronized (this.b)
    {
      this.d = paramInt2;
      this.e += 1;
      ??? = zzD(paramIntent);
      if (??? == null)
      {
        a(paramIntent);
        return 2;
      }
    }
    if (zzE((Intent)???))
    {
      a(paramIntent);
      return 2;
    }
    this.c.execute(new Runnable()
    {
      public final void run()
      {
        zzb.this.handleIntent(localObject);
        zzb.a(zzb.this, paramIntent);
      }
    });
    return 3;
  }
  
  protected Intent zzD(Intent paramIntent)
  {
    return paramIntent;
  }
  
  public boolean zzE(Intent paramIntent)
  {
    return false;
  }
  
  public static class zza
    extends Binder
  {
    private final zzb a;
    
    zza(zzb paramzzb)
    {
      this.a = paramzzb;
    }
    
    private static void b(@Nullable BroadcastReceiver.PendingResult paramPendingResult)
    {
      if (paramPendingResult != null) {
        paramPendingResult.finish();
      }
    }
    
    public void zza(final Intent paramIntent, @Nullable final BroadcastReceiver.PendingResult paramPendingResult)
    {
      if (Binder.getCallingUid() != Process.myUid()) {
        throw new SecurityException("Binding only allowed within app");
      }
      Log.isLoggable("EnhancedIntentService", 3);
      if (this.a.zzE(paramIntent))
      {
        b(paramPendingResult);
        return;
      }
      Log.isLoggable("EnhancedIntentService", 3);
      this.a.c.execute(new Runnable()
      {
        public final void run()
        {
          Log.isLoggable("EnhancedIntentService", 3);
          zzb.this.handleIntent(paramIntent);
          zzb.zza.a(paramPendingResult);
        }
      });
    }
  }
  
  public static class zzb
    implements ServiceConnection
  {
    private final Context a;
    private final Intent b;
    private final Queue<Pair<Intent, BroadcastReceiver.PendingResult>> c = new LinkedList();
    private zzb.zza d;
    private boolean e = false;
    
    public zzb(Context paramContext, String paramString)
    {
      this.a = paramContext.getApplicationContext();
      this.b = new Intent(paramString).setPackage(this.a.getPackageName());
    }
    
    private void a()
    {
      try
      {
        Log.isLoggable("EnhancedIntentService", 3);
        for (;;)
        {
          if (this.c.isEmpty()) {
            break label165;
          }
          Log.isLoggable("EnhancedIntentService", 3);
          if ((this.d == null) || (!this.d.isBinderAlive())) {
            break;
          }
          Log.isLoggable("EnhancedIntentService", 3);
          Pair localPair = (Pair)this.c.poll();
          this.d.zza((Intent)localPair.first, (BroadcastReceiver.PendingResult)localPair.second);
        }
        if (!Log.isLoggable("EnhancedIntentService", 3)) {
          break label131;
        }
      }
      finally {}
      boolean bool;
      if (!this.e)
      {
        bool = true;
        new StringBuilder(39).append("binder is dead. start connection? ").append(bool);
        label131:
        if (!this.e) {
          this.e = true;
        }
      }
      for (;;)
      {
        try
        {
          bool = zza.zzyJ().zza(this.a, this.b, this, 65);
          if (bool)
          {
            label165:
            return;
            bool = false;
            break;
          }
          Log.e("EnhancedIntentService", "binding to the service failed");
        }
        catch (SecurityException localSecurityException)
        {
          Log.e("EnhancedIntentService", "Exception while binding the service", localSecurityException);
          continue;
        }
        if (!this.c.isEmpty()) {
          ((BroadcastReceiver.PendingResult)((Pair)this.c.poll()).second).finish();
        }
      }
    }
    
    public void onServiceConnected(ComponentName paramComponentName, IBinder paramIBinder)
    {
      try
      {
        this.e = false;
        this.d = ((zzb.zza)paramIBinder);
        if (Log.isLoggable("EnhancedIntentService", 3))
        {
          paramComponentName = String.valueOf(paramComponentName);
          new StringBuilder(String.valueOf(paramComponentName).length() + 20).append("onServiceConnected: ").append(paramComponentName);
        }
        a();
        return;
      }
      finally {}
    }
    
    public void onServiceDisconnected(ComponentName paramComponentName)
    {
      if (Log.isLoggable("EnhancedIntentService", 3))
      {
        paramComponentName = String.valueOf(paramComponentName);
        new StringBuilder(String.valueOf(paramComponentName).length() + 23).append("onServiceDisconnected: ").append(paramComponentName);
      }
      a();
    }
    
    public void zzb(Intent paramIntent, BroadcastReceiver.PendingResult paramPendingResult)
    {
      try
      {
        Log.isLoggable("EnhancedIntentService", 3);
        this.c.add(new Pair(paramIntent, paramPendingResult));
        a();
        return;
      }
      finally
      {
        paramIntent = finally;
        throw paramIntent;
      }
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/google/firebase/iid/zzb.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */