package com.tealium.library;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Locale;
import org.json.JSONObject;

final class ag extends RemoteCommand
{
  private final Context a;
  private final Object b;
  private final Method c;
  private final SharedPreferences d;

  private ag(Context paramContext, Object paramObject, Method paramMethod, SharedPreferences paramSharedPreferences)
  {
    super("_push", "Register this device to receive Push events.");
    this.a = paramContext.getApplicationContext();
    this.b = paramObject;
    this.c = paramMethod;
    this.d = paramSharedPreferences;
  }

  static ag a(Context paramContext, List<String> paramList, SharedPreferences paramSharedPreferences)
  {
    try
    {
      Class localClass1 = Class.forName("com.google.android.gms.common.GooglePlayServicesUtil");
      Method localMethod = localClass1.getMethod("isGooglePlayServicesAvailable", new Class[] { Context.class });
      Class localClass2 = Class.forName("com.google.android.gms.common.ConnectionResult");
      Field localField = localClass2.getField("SUCCESS");
      if (((Integer)localMethod.invoke(localClass1, new Object[] { paramContext })).intValue() != localField.getInt(localClass2))
      {
        paramList.add("Unable to initialze Push capabilities, Google Play Services are unavailable.");
        return null;
      }
      if ((paramContext.checkCallingOrSelfPermission("android.permission.GET_ACCOUNTS") != 0) && (Build.VERSION.SDK_INT < 16))
      {
        paramList.add(String.format(Locale.ROOT, "Unable to create _push, missing %s", new Object[] { "android.permission.GET_ACCOUNTS" }));
        return null;
      }
      Locale localLocale = Locale.ROOT;
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = paramContext.getPackageName();
      String str = String.format(localLocale, "%s.permission.C2D_MESSAGE", arrayOfObject);
      if (paramContext.checkCallingOrSelfPermission(str) != 0)
      {
        paramList.add(String.format(Locale.ROOT, "Unable to create _push, missing %s", new Object[] { str }));
        return null;
      }
      Class localClass3 = Class.forName("com.google.android.gms.gcm.GoogleCloudMessaging");
      ag localag = new ag(paramContext, localClass3.getMethod("getInstance", new Class[] { Context.class }).invoke(localClass3, new Object[] { paramContext }), localClass3.getMethod("register", new Class[] { [Ljava.lang.String.class }), paramSharedPreferences);
      return localag;
    }
    catch (Throwable localThrowable)
    {
      paramList.add("Unable to initialize Push capabilites, the Google Play Services Library is either not present, or an incompatible version.");
    }
    return null;
  }

  public final void onRemoteCommandInvoke(JSONObject paramJSONObject)
    throws Throwable
  {
    final String str1 = paramJSONObject.optString("project_number", null);
    if (str1 == null)
    {
      X.d("Missing required argument \"project_number\" for Push Remote Command");
      setResult(RemoteCommand.RESULT_BAD_REQUEST, null);
      return;
    }
    String str2 = Y.a.a(this.a);
    final String str3 = String.format(Locale.ROOT, "push_token_%s_%s", new Object[] { str1, str2 });
    if (Tealium.getGlobalCustomData().getString("app_version", "").equals(str2))
    {
      String str4 = this.d.getString(str3, null);
      if (str4 != null)
      {
        setResult(RemoteCommand.RESULT_OK, str4);
        return;
      }
    }
    paramJSONObject.optString("response_id", null);
    AsyncTask local1 = new AsyncTask()
    {
      private Void a()
      {
        try
        {
          String[] arrayOfString = new String[1];
          arrayOfString[0] = str1;
          String str = (String)ag.b(ag.this).invoke(ag.a(ag.this), new Object[] { arrayOfString });
          ag.c(ag.this).edit().putString(str3, str).commit();
          Tealium.getGlobalCustomData().edit().putString("device_push_token", str).commit();
          ag.this.setResult(RemoteCommand.RESULT_OK, str);
          return null;
        }
        catch (Throwable localThrowable)
        {
          while (true)
          {
            ag.this.setResult(RemoteCommand.RESULT_EXCEPTION_THROWN, ad.a(localThrowable));
            X.b(localThrowable);
          }
        }
      }
    };
    if (Build.VERSION.SDK_INT >= 11)
    {
      local1.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
      return;
    }
    local1.execute(new Void[0]);
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.tealium.library.ag
 * JD-Core Version:    0.6.2
 */