导航菜单

页面标题

页面副标题

Vi App v10.18.0 - ParsePushBroadcastReceiver.java 源代码

正在查看: Vi App v10.18.0 应用的 ParsePushBroadcastReceiver.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.parse;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import java.util.Random;
import org.json.JSONException;
import org.json.JSONObject;

public class ParsePushBroadcastReceiver extends BroadcastReceiver {
    @TargetApi(26)
    public void createNotificationChannel(Context context, NotificationChannel notificationChannel) {
        androidx.browser.trusted.a.a((NotificationManager) context.getSystemService("notification"), notificationChannel);
    }

    public Class<? extends Activity> getActivity(Context context, Intent intent) {
        Intent launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        if (launchIntentForPackage == null) {
            return null;
        }
        try {
            return Class.forName(launchIntentForPackage.getComponent().getClassName());
        } catch (ClassNotFoundException unused) {
            return null;
        }
    }

    public Intent getContentIntent(Bundle bundle, String str) {
        Intent intent = new Intent("com.parse.push.intent.OPEN");
        intent.putExtras(bundle);
        intent.setPackage(str);
        return intent;
    }

    public Intent getDeleteIntent(Bundle bundle, String str) {
        Intent intent = new Intent("com.parse.push.intent.DELETE");
        intent.putExtras(bundle);
        intent.setPackage(str);
        return intent;
    }

    public Bitmap getLargeIcon(Context context, Intent intent) {
        return null;
    }

    @Nullable
    public NotificationCompat.Builder getNotification(Context context, Intent intent) {
        JSONObject pushData = getPushData(intent);
        String str = null;
        if (pushData == null || !(pushData.has("alert") || pushData.has("title"))) {
            return null;
        }
        String optString = pushData.optString("title", ManifestInfo.getDisplayName(context));
        String optString2 = pushData.optString("alert", "Notification received.");
        String format = String.format("%s: %s", optString, optString2);
        Bundle extras = intent.getExtras();
        Random random = new Random();
        int nextInt = random.nextInt();
        int nextInt2 = random.nextInt();
        String packageName = context.getPackageName();
        Intent contentIntent = getContentIntent(extras, packageName);
        Intent deleteIntent = getDeleteIntent(extras, packageName);
        int i = Build.VERSION.SDK_INT;
        int i2 = i >= 30 ? 201326592 : 134217728;
        PendingIntent broadcast = PendingIntent.getBroadcast(context, nextInt, contentIntent, i2);
        PendingIntent broadcast2 = PendingIntent.getBroadcast(context, nextInt2, deleteIntent, i2);
        if (i >= 26) {
            NotificationChannel notificationChannel = getNotificationChannel(context, intent);
            createNotificationChannel(context, notificationChannel);
            str = notificationChannel.getId();
        }
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, str);
        builder.setContentTitle(optString).setContentText(optString2).setTicker(format).setSmallIcon(getSmallIconId(context, intent)).setLargeIcon(getLargeIcon(context, intent)).setContentIntent(broadcast).setDeleteIntent(broadcast2).setAutoCancel(true).setDefaults(-1);
        if (optString2.length() > 38) {
            builder.setStyle(new NotificationCompat.BigTextStyle().bigText(optString2));
        }
        return builder;
    }

    @TargetApi(26)
    public NotificationChannel getNotificationChannel(Context context, Intent intent) {
        return new NotificationChannel("parse_push", "Push notifications", 3);
    }

    public JSONObject getPushData(Intent intent) {
        try {
            return new JSONObject(intent.getStringExtra("com.parse.Data"));
        } catch (JSONException e) {
            PLog.e("com.parse.ParsePushReceiver", "Unexpected JSONException when receiving push data: ", e);
            return null;
        }
    }

    public int getSmallIconId(Context context, Intent intent) {
        Bundle applicationMetadata = ManifestInfo.getApplicationMetadata(context);
        int i = applicationMetadata != null ? applicationMetadata.getInt("com.parse.push.notification_icon") : 0;
        return i != 0 ? i : ManifestInfo.getIconId();
    }

    public void onPushDismiss(Context context, Intent intent) {
    }

    public void onPushOpen(Context context, Intent intent) {
        ParseAnalytics.trackAppOpenedInBackground(intent);
        String str = null;
        try {
            str = new JSONObject(intent.getStringExtra("com.parse.Data")).optString("uri", null);
        } catch (JSONException e) {
            PLog.e("com.parse.ParsePushReceiver", "Unexpected JSONException when receiving push data: ", e);
        }
        Class<? extends Activity> activity = getActivity(context, intent);
        Intent intent2 = str != null ? new Intent("android.intent.action.VIEW", Uri.parse(str)) : new Intent(context, activity);
        intent2.putExtras(intent.getExtras());
        TaskStackBuilderHelper.startActivities(context, activity, intent2);
    }

    public void onPushReceive(Context context, Intent intent) {
        JSONObject jSONObject;
        String stringExtra = intent.getStringExtra("com.parse.Data");
        if (stringExtra == null) {
            PLog.e("com.parse.ParsePushReceiver", "Can not get push data from intent.");
            return;
        }
        PLog.v("com.parse.ParsePushReceiver", "Received push data: " + stringExtra);
        try {
            jSONObject = new JSONObject(stringExtra);
        } catch (JSONException e) {
            PLog.e("com.parse.ParsePushReceiver", "Unexpected JSONException when receiving push data: ", e);
            jSONObject = null;
        }
        String optString = jSONObject != null ? jSONObject.optString("action", null) : null;
        if (optString != null) {
            Bundle extras = intent.getExtras();
            Intent intent2 = new Intent();
            intent2.putExtras(extras);
            intent2.setAction(optString);
            intent2.setPackage(context.getPackageName());
            context.sendBroadcast(intent2);
        }
        NotificationCompat.Builder notification = getNotification(context, intent);
        Notification build = notification != null ? notification.build() : null;
        if (build != null) {
            ParseNotificationManager.getInstance().showNotification(context, build);
        }
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action != null) {
            switch (action) {
                case "com.parse.push.intent.DELETE":
                    onPushDismiss(context, intent);
                    break;
                case "com.parse.push.intent.RECEIVE":
                    onPushReceive(context, intent);
                    break;
                case "com.parse.push.intent.OPEN":
                    onPushOpen(context, intent);
                    break;
            }
        }
    }
}