ADMRegistrar.java 4.2 KB
package com.arellomobile.android.push;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.util.Log;
import com.amazon.device.messaging.ADM;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public final class ADMRegistrar
{
  public static final String INTENT_FROM_ADM_MESSAGE = "com.amazon.device.messaging.intent.RECEIVE";
  public static final String INTENT_FROM_ADM_REGISTRATION_CALLBACK = "com.amazon.device.messaging.intent.REGISTRATION";
  public static final String PERMISSION_ADM_INTENTS = "com.amazon.device.messaging.permission.SEND";
  
  private static void a(Context paramContext, Set<String> paramSet, String paramString)
  {
    PackageManager localPackageManager = paramContext.getPackageManager();
    paramContext = paramContext.getPackageName();
    Intent localIntent = new Intent(paramString);
    localIntent.setPackage(paramContext);
    paramContext = localPackageManager.queryBroadcastReceivers(localIntent, 32);
    if (paramContext.isEmpty()) {
      throw new IllegalStateException("No receivers for action " + paramString);
    }
    if (Log.isLoggable("ADMRegistrar", 2)) {
      Log.v("ADMRegistrar", "Found " + paramContext.size() + " receivers for action " + paramString);
    }
    paramContext = paramContext.iterator();
    while (paramContext.hasNext())
    {
      paramString = ((ResolveInfo)paramContext.next()).activityInfo.name;
      if (!paramSet.contains(paramString)) {
        throw new IllegalStateException("Receiver " + paramString + " is not set with permission com.amazon.device.messaging.permission.SEND");
      }
    }
  }
  
  public static void checkDevice(ADM paramADM)
  {
    if (!paramADM.isSupported()) {
      throw new UnsupportedOperationException("ADM is not supported on the current device");
    }
  }
  
  public static void checkManifest(Context paramContext)
  {
    PackageManager localPackageManager = paramContext.getPackageManager();
    Object localObject1 = paramContext.getPackageName();
    Object localObject2 = (String)localObject1 + ".permission.RECEIVE_ADM_MESSAGE";
    try
    {
      localPackageManager.getPermissionInfo((String)localObject2, 4096);
      if (!Log.isLoggable("ADMRegistrar", 2)) {
        break label187;
      }
    }
    catch (PackageManager.NameNotFoundException paramContext)
    {
      try
      {
        localObject2 = localPackageManager.getPackageInfo((String)localObject1, 2);
        localObject2 = ((PackageInfo)localObject2).receivers;
        if ((localObject2 != null) && (localObject2.length != 0)) {
          break label145;
        }
        throw new IllegalStateException("No receiver for package " + (String)localObject1);
      }
      catch (PackageManager.NameNotFoundException paramContext)
      {
        throw new IllegalStateException("Could not get receivers for package " + (String)localObject1);
      }
      paramContext = paramContext;
      throw new IllegalStateException("Application does not define permission " + (String)localObject2);
    }
    label145:
    Log.v("ADMRegistrar", "number of receivers for " + (String)localObject1 + ": " + localObject2.length);
    label187:
    localObject1 = new HashSet();
    int j = localObject2.length;
    int i = 0;
    while (i < j)
    {
      localPackageManager = localObject2[i];
      if ("com.amazon.device.messaging.permission.SEND".equals(localPackageManager.permission)) {
        ((Set)localObject1).add(localPackageManager.name);
      }
      i += 1;
    }
    if (((Set)localObject1).isEmpty()) {
      throw new IllegalStateException("No receiver allowed to receive com.amazon.device.messaging.permission.SEND");
    }
    a(paramContext, (Set)localObject1, "com.amazon.device.messaging.intent.REGISTRATION");
    a(paramContext, (Set)localObject1, "com.amazon.device.messaging.intent.RECEIVE");
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/arellomobile/android/push/ADMRegistrar.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */