DeviceRegistrar.java 2.79 KB
package com.arellomobile.android.push;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.arellomobile.android.push.request.RegisterDeviceRequest;
import com.arellomobile.android.push.request.RequestManager;
import com.arellomobile.android.push.request.UnregisterDeviceRequest;
import com.arellomobile.android.push.utils.PreferenceUtils;
import com.google.android.gcm.GCMRegistrar;
import java.util.Date;

public class DeviceRegistrar
{
  static void a(Context paramContext, String paramString)
  {
    Log.w("DeviceRegistrar", "Registering for pushes");
    RegisterDeviceRequest localRegisterDeviceRequest = new RegisterDeviceRequest(paramString);
    try
    {
      RequestManager.sendRequest(paramContext, localRegisterDeviceRequest);
      GCMRegistrar.setRegisteredOnServer(paramContext, true);
      PushEventsTransmitter.a(paramContext, paramString);
      PreferenceUtils.setLastRegistration(paramContext, new Date().getTime());
      Log.w("DeviceRegistrar", "Registered for pushes: " + paramString);
      return;
    }
    catch (Exception paramString)
    {
      if (paramString.getMessage() != null)
      {
        PushEventsTransmitter.b(paramContext, paramString.getMessage());
        Log.e("DeviceRegistrar", "Registration error " + paramString.getMessage(), paramString);
        return;
      }
      paramString = localRegisterDeviceRequest.getRawResponse();
      Log.e("DeviceRegistrar", "Registration error " + paramString);
      PushEventsTransmitter.b(paramContext, paramString);
    }
  }
  
  static void b(Context paramContext, String paramString)
  {
    Log.w("DeviceRegistrar", "Try To Unregistered for pushes");
    GCMRegistrar.setRegisteredOnServer(paramContext, false);
    UnregisterDeviceRequest localUnregisterDeviceRequest = new UnregisterDeviceRequest();
    try
    {
      RequestManager.sendRequest(paramContext, localUnregisterDeviceRequest);
      PushEventsTransmitter.c(paramContext, paramString);
      Log.w("DeviceRegistrar", "Unregistered for pushes: " + paramString);
      PreferenceUtils.resetLastRegistration(paramContext);
      return;
    }
    catch (Exception paramString)
    {
      if (!TextUtils.isEmpty(paramString.getMessage()))
      {
        PushEventsTransmitter.d(paramContext, paramString.getMessage());
        Log.e("DeviceRegistrar", "Unregistration error " + paramString.getMessage(), paramString);
        return;
      }
      paramString = localUnregisterDeviceRequest.getRawResponse();
      PushEventsTransmitter.d(paramContext, paramString);
      Log.e("DeviceRegistrar", "Unregistration error " + paramString);
    }
  }
}


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