PushServiceHelper.java 6.75 KB
package com.arellomobile.android.push;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import com.arellomobile.android.push.utils.GeneralUtils;
import com.arellomobile.android.push.utils.PreferenceUtils;
import com.arellomobile.android.push.utils.notification.BannerNotificationFactory;
import com.arellomobile.android.push.utils.notification.BaseNotificationFactory;
import com.arellomobile.android.push.utils.notification.SimpleNotificationFactory;
import java.util.Iterator;
import java.util.Set;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class PushServiceHelper
{
  public static void generateBroadcast(Context paramContext, Bundle paramBundle)
  {
    Intent localIntent = new Intent();
    localIntent.setAction(paramContext.getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");
    localIntent.putExtras(paramBundle);
    JSONObject localJSONObject2 = new JSONObject();
    Iterator localIterator = paramBundle.keySet().iterator();
    if (localIterator.hasNext())
    {
      String str = (String)localIterator.next();
      if (str.equals("u")) {}
      for (;;)
      {
        try
        {
          localObject2 = paramBundle.get("u");
          if ((localObject2 != null) && ((localObject2 instanceof String)))
          {
            if (!((String)localObject2).startsWith("{")) {
              continue;
            }
            JSONObject localJSONObject1 = new JSONObject((String)localObject2);
            localJSONObject2.put("userdata", localJSONObject1);
          }
        }
        catch (JSONException localJSONException2)
        {
          Object localObject2;
          Object localObject1;
          continue;
        }
        try
        {
          localJSONObject2.put(str, paramBundle.get(str));
        }
        catch (JSONException localJSONException1) {}
        break;
        localObject1 = localObject2;
        if (((String)localObject2).startsWith("[")) {
          localObject1 = new JSONArray((String)localObject2);
        }
      }
    }
    localIntent.putExtra("pw_data_json_string", localJSONObject2.toString());
    if (GeneralUtils.isAmazonDevice())
    {
      paramContext.sendBroadcast(localIntent, paramContext.getPackageName() + ".permission.RECEIVE_ADM_MESSAGE");
      return;
    }
    paramContext.sendBroadcast(localIntent, paramContext.getPackageName() + ".permission.C2D_MESSAGE");
  }
  
  public static void generateNotification(Context paramContext, Intent paramIntent)
  {
    Bundle localBundle = paramIntent.getExtras();
    if (localBundle == null) {
      return;
    }
    localBundle.putBoolean("foreground", GeneralUtils.isAppOnForeground(paramContext));
    boolean bool;
    label33:
    String str1;
    Object localObject1;
    label102:
    Object localObject2;
    if (!GeneralUtils.isAppOnForeground(paramContext))
    {
      bool = true;
      localBundle.putBoolean("onStart", bool);
      str1 = (String)localBundle.get("title");
      localObject1 = (String)localBundle.get("header");
      paramIntent = (String)localBundle.get("l");
      if (paramIntent == null) {
        break label341;
      }
      paramIntent = new Intent("android.intent.action.VIEW", Uri.parse(paramIntent));
      paramIntent.addFlags(268435456);
      if (localObject1 != null) {
        break label401;
      }
      localObject2 = paramContext.getPackageManager().getApplicationLabel(paramContext.getApplicationInfo());
      localObject1 = localObject2;
      if (localObject2 == null) {
        localObject1 = "";
      }
      localObject1 = localObject1.toString();
    }
    label341:
    label401:
    for (;;)
    {
      localObject2 = (NotificationManager)paramContext.getSystemService("notification");
      String str2 = (String)localBundle.get("b");
      if ((paramContext.getResources().getIdentifier("notification", "layout", paramContext.getPackageName()) != 0) && (str2 != null)) {}
      for (localObject1 = new BannerNotificationFactory(paramContext, localBundle, (String)localObject1, str1, PreferenceUtils.getSoundType(paramContext), PreferenceUtils.getVibrateType(paramContext));; localObject1 = new SimpleNotificationFactory(paramContext, localBundle, (String)localObject1, str1, PreferenceUtils.getSoundType(paramContext), PreferenceUtils.getVibrateType(paramContext)))
      {
        ((BaseNotificationFactory)localObject1).generateNotification();
        ((BaseNotificationFactory)localObject1).addSoundAndVibrate();
        ((BaseNotificationFactory)localObject1).addCancel();
        if (PreferenceUtils.getEnableLED(paramContext)) {
          ((BaseNotificationFactory)localObject1).addLED(true);
        }
        localObject1 = ((BaseNotificationFactory)localObject1).getNotification();
        int j = PreferenceUtils.getMessageId(paramContext);
        int i = j;
        if (PreferenceUtils.getMultiMode(paramContext) == true)
        {
          i = j + 1;
          PreferenceUtils.setMessageId(paramContext, i);
        }
        ((Notification)localObject1).contentIntent = PendingIntent.getActivity(paramContext, i, paramIntent, 268435456);
        if (!localBundle.getBoolean("silent", false)) {
          ((NotificationManager)localObject2).notify(i, (Notification)localObject1);
        }
        generateBroadcast(paramContext, localBundle);
        if (localBundle.getBoolean("local", false)) {
          break;
        }
        try
        {
          DeviceFeature2_5.sendMessageDeliveryEvent(paramContext, localBundle.getString("p"));
          return;
        }
        catch (Exception paramContext)
        {
          return;
        }
        bool = false;
        break label33;
        paramIntent = new Intent(paramContext, PushHandlerActivity.class);
        paramIntent.addFlags(603979776);
        paramIntent.putExtra("pushBundle", localBundle);
        break label102;
      }
    }
  }
  
  public static String getPushServiceClassName(Context paramContext)
  {
    try
    {
      paramContext = paramContext.getPackageManager().getApplicationInfo(paramContext.getApplicationContext().getPackageName(), 128);
      if (paramContext.metaData != null)
      {
        paramContext = paramContext.metaData.getString("PW_PUSH_SERVICE");
        if (paramContext != null) {
          return paramContext;
        }
      }
    }
    catch (Exception paramContext) {}
    return "com.arellomobile.android.push.PushGCMIntentService";
  }
}


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