package tv.ouya.console.api;

import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import tv.ouya.console.internal.GamerInfoListenerBinder;
import tv.ouya.console.internal.IIapServiceDefinition;
import tv.ouya.console.internal.IIapServiceDefinition.Stub;
import tv.ouya.console.internal.ProductListListenerBinder;
import tv.ouya.console.internal.StringListenerBinder;

public class OuyaFacade
  implements ServiceConnection
{
  private static final String[] ALL_DATA_COLUMNS = { "property_name", "value" };
  private static final String LOG_TAG = "OUYAF";
  static final int ODK_VERSION_NUMBER = 62;
  private static final String[] USER_DATA_COLUMNS = { "value" };
  private static OuyaFacade instance = new OuyaFacade();
  private boolean bindRequestHasBeenMade;
  private Context context;
  private String developerId;
  private List<Runnable> pendingRequests = new ArrayList();
  private IIapServiceDefinition remoteService;
  
  OuyaFacade()
  {
    Log.v("OUYAF", "ODK version number: 62");
  }
  
  public static OuyaFacade getInstance()
  {
    return instance;
  }
  
  public static int getOdkVersionNumber()
  {
    return 62;
  }
  
  private void runRequest(Runnable paramRunnable)
  {
    ensureServiceIsBound();
    if (this.remoteService != null)
    {
      paramRunnable.run();
      return;
    }
    this.pendingRequests.add(paramRunnable);
  }
  
  @Deprecated
  static void setInstance(OuyaFacade paramOuyaFacade)
  {
    instance = paramOuyaFacade;
  }
  
  @Deprecated
  public boolean bindRequestHasBeenMade()
  {
    return this.bindRequestHasBeenMade;
  }
  
  void ensureServiceIsBound()
  {
    if (this.context == null) {
      Log.e("OUYAF", "Dropping request because connect has been shut down");
    }
    while (this.bindRequestHasBeenMade) {
      return;
    }
    Log.d("inAppPurchase", "Binding to IapService");
    Intent localIntent = new Intent();
    localIntent.setClassName("tv.ouya", "tv.ouya.console.service.iap.IapService");
    this.context.bindService(localIntent, this, 1);
    this.bindRequestHasBeenMade = true;
  }
  
  /* Error */
  public java.util.Map<String, String> getAllGameData()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 119	tv/ouya/console/api/OuyaFacade:context	Landroid/content/Context;
    //   4: invokevirtual 154	android/content/Context:getContentResolver	()Landroid/content/ContentResolver;
    //   7: ldc -100
    //   9: invokestatic 162	android/net/Uri:parse	(Ljava/lang/String;)Landroid/net/Uri;
    //   12: getstatic 62	tv/ouya/console/api/OuyaFacade:ALL_DATA_COLUMNS	[Ljava/lang/String;
    //   15: aconst_null
    //   16: aconst_null
    //   17: aconst_null
    //   18: aconst_null
    //   19: invokevirtual 168	android/content/ContentResolver:query	(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Landroid/os/CancellationSignal;)Landroid/database/Cursor;
    //   22: astore_2
    //   23: aconst_null
    //   24: astore_1
    //   25: aload_2
    //   26: invokeinterface 173 1 0
    //   31: ifeq +39 -> 70
    //   34: aload_1
    //   35: ifnonnull +56 -> 91
    //   38: new 175	java/util/HashMap
    //   41: dup
    //   42: invokespecial 176	java/util/HashMap:<init>	()V
    //   45: astore_1
    //   46: aload_1
    //   47: aload_2
    //   48: iconst_0
    //   49: invokeinterface 180 2 0
    //   54: aload_2
    //   55: iconst_1
    //   56: invokeinterface 180 2 0
    //   61: invokeinterface 186 3 0
    //   66: pop
    //   67: goto -42 -> 25
    //   70: aload_2
    //   71: invokeinterface 189 1 0
    //   76: aload_1
    //   77: areturn
    //   78: astore_1
    //   79: aload_2
    //   80: invokeinterface 189 1 0
    //   85: aload_1
    //   86: athrow
    //   87: astore_1
    //   88: goto -9 -> 79
    //   91: goto -45 -> 46
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	94	0	this	OuyaFacade
    //   24	53	1	localHashMap	java.util.HashMap
    //   78	8	1	localObject1	Object
    //   87	1	1	localObject2	Object
    //   22	58	2	localCursor	Cursor
    // Exception table:
    //   from	to	target	type
    //   25	34	78	finally
    //   38	46	78	finally
    //   46	67	87	finally
  }
  
  public String getGameData(String paramString)
  {
    paramString = this.context.getContentResolver().query(Uri.parse("content://tv.ouya.userdata/settings/" + paramString), USER_DATA_COLUMNS, "property_name = ?", new String[] { paramString }, null, null);
    try
    {
      if (paramString.moveToNext())
      {
        String str = paramString.getString(0);
        return str;
      }
      return null;
    }
    finally
    {
      paramString.close();
    }
  }
  
  @Deprecated
  IIapServiceDefinition getRemoteService()
  {
    return this.remoteService;
  }
  
  public void init(Context paramContext, String paramString)
  {
    if (isInitialized()) {
      return;
    }
    this.context = paramContext.getApplicationContext();
    this.developerId = paramString;
  }
  
  public boolean isInitialized()
  {
    return this.context != null;
  }
  
  public boolean isRunningOnOUYAHardware()
  {
    if (("cardhu".equals(Build.DEVICE)) || ("ouya_1_1".equals(Build.DEVICE))) {}
    for (boolean bool = true;; bool = false)
    {
      if (!bool) {
        Log.w("OUYAF", "Not running on Ouya hardware: " + Build.DEVICE);
      }
      return bool;
    }
  }
  
  public void onServiceConnected(ComponentName paramComponentName, IBinder paramIBinder)
  {
    Log.d("inAppPurchase", "Successfully bound to IapService");
    this.remoteService = IIapServiceDefinition.Stub.asInterface(paramIBinder);
    while (this.pendingRequests.size() > 0) {
      ((Runnable)this.pendingRequests.remove(0)).run();
    }
  }
  
  public void onServiceDisconnected(ComponentName paramComponentName)
  {
    this.remoteService = null;
    this.bindRequestHasBeenMade = false;
  }
  
  public void putGameData(String paramString1, String paramString2)
  {
    ContentValues localContentValues = new ContentValues();
    localContentValues.put("value", paramString2);
    paramString2 = new String[1];
    paramString2[0] = paramString1;
    if (this.context.getContentResolver().query(Uri.parse("content://tv.ouya.userdata/settings/" + paramString1), null, "property_name = ?", paramString2, null).getCount() > 0)
    {
      this.context.getContentResolver().update(Uri.parse("content://tv.ouya.userdata/settings/" + paramString1), localContentValues, "property_name = ?", paramString2);
      return;
    }
    this.context.getContentResolver().insert(Uri.parse("content://tv.ouya.userdata/settings/" + paramString1), localContentValues);
  }
  
  public void requestGamerInfo(OuyaResponseListener<GamerInfo> paramOuyaResponseListener)
  {
    runRequest(new RequestGamerInfoRunnable(paramOuyaResponseListener));
  }
  
  public void requestGamerUuid(OuyaResponseListener<String> paramOuyaResponseListener)
  {
    runRequest(new RequestGamerUuidRunnable(paramOuyaResponseListener));
  }
  
  public void requestProductList(List<Purchasable> paramList, OuyaResponseListener<ArrayList<Product>> paramOuyaResponseListener)
  {
    runRequest(new RequestProductListRunnable(paramList, paramOuyaResponseListener));
  }
  
  public void requestPurchase(Purchasable paramPurchasable, OuyaResponseListener<String> paramOuyaResponseListener)
  {
    runRequest(new RequestPurchaseRunnable(paramPurchasable, paramOuyaResponseListener));
  }
  
  public void requestReceipts(OuyaResponseListener<String> paramOuyaResponseListener)
  {
    runRequest(new RequestReceiptsRunnable(paramOuyaResponseListener, null));
  }
  
  public void setTestMode()
  {
    runRequest(new SetTestModeRunnable());
  }
  
  public void shutdown()
  {
    if (this.context != null)
    {
      if (this.remoteService != null)
      {
        this.context.unbindService(this);
        this.remoteService = null;
        this.bindRequestHasBeenMade = false;
      }
      this.context = null;
    }
  }
  
  private class RequestGamerInfoRunnable
    extends RequestRunnable
  {
    public RequestGamerInfoRunnable()
    {
      super("fetching gamer info");
    }
    
    void doRun()
      throws RemoteException
    {
      OuyaFacade.this.remoteService.requestGamerInfo(OuyaFacade.this.developerId, new GamerInfoListenerBinder(this.listener));
    }
  }
  
  private class RequestGamerUuidRunnable
    extends RequestRunnable
  {
    public RequestGamerUuidRunnable()
    {
      super("fetching gamer UUID");
    }
    
    void doRun()
      throws RemoteException
    {
      OuyaFacade.this.remoteService.requestGamerUuid(OuyaFacade.this.developerId, new StringListenerBinder(this.listener));
    }
  }
  
  private class RequestProductListRunnable
    extends RequestRunnable
  {
    private final List<Purchasable> purchasables;
    
    public RequestProductListRunnable(OuyaResponseListener<ArrayList<Product>> paramOuyaResponseListener)
    {
      super("fetching product list");
      this.purchasables = paramOuyaResponseListener;
    }
    
    void doRun()
      throws RemoteException
    {
      OuyaFacade.this.remoteService.requestProductListForVersion(OuyaFacade.this.developerId, 4, this.purchasables, new ProductListListenerBinder(this.listener));
    }
  }
  
  private class RequestPurchaseRunnable
    extends RequestRunnable
  {
    private final Purchasable purchasable;
    
    public RequestPurchaseRunnable(OuyaResponseListener<String> paramOuyaResponseListener)
    {
      super("purchasing");
      this.purchasable = paramOuyaResponseListener;
    }
    
    void doRun()
      throws RemoteException
    {
      OuyaFacade.this.remoteService.requestPurchase(OuyaFacade.this.developerId, this.purchasable, new StringListenerBinder(this.listener));
    }
  }
  
  private class RequestReceiptsRunnable
    extends RequestRunnable
  {
    private RequestReceiptsRunnable()
    {
      super("fetching receipts");
    }
    
    void doRun()
      throws RemoteException
    {
      OuyaFacade.this.remoteService.requestReceipts(OuyaFacade.this.developerId, new StringListenerBinder(this.listener));
    }
  }
  
  private class SetTestModeRunnable
    extends RequestRunnable
  {
    public SetTestModeRunnable()
    {
      super(
      {
        public void onCancel() {}
        
        public void onFailure(int paramAnonymousInt, String paramAnonymousString, Bundle paramAnonymousBundle) {}
        
        public void onSuccess(Object paramAnonymousObject) {}
      });
    }
    
    void doRun()
      throws RemoteException
    {
      OuyaFacade.this.remoteService.setTestMode();
    }
  }
}


/* Location:              /home/enzo/Documents/hacking/malwares/viking-horde/classes.jar!/tv/ouya/console/api/OuyaFacade.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */