正在查看: Jurassic World v1.83.4 应用的 NotificationIntentProcessor.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Jurassic World v1.83.4 应用的 NotificationIntentProcessor.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.urbanairship.push;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.core.app.NotificationManagerCompat;
import com.urbanairship.AirshipExecutors;
import com.urbanairship.Logger;
import com.urbanairship.PendingResult;
import com.urbanairship.UAirship;
import com.urbanairship.actions.ActionArguments;
import com.urbanairship.actions.ActionCompletionCallback;
import com.urbanairship.actions.ActionResult;
import com.urbanairship.actions.ActionRunRequest;
import com.urbanairship.actions.ActionValue;
import com.urbanairship.analytics.InteractiveNotificationEvent;
import com.urbanairship.json.JsonException;
import com.urbanairship.json.JsonMap;
import com.urbanairship.json.JsonValue;
import com.urbanairship.util.UAStringUtil;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
class NotificationIntentProcessor {
private final NotificationActionButtonInfo actionButtonInfo;
private final UAirship airship;
private final Context context;
private final Executor executor;
private final Intent intent;
private final NotificationInfo notificationInfo;
NotificationIntentProcessor(Context context, Intent intent) {
this(UAirship.shared(), context, intent, AirshipExecutors.threadPoolExecutor());
}
NotificationIntentProcessor(UAirship airship, Context context, Intent intent, Executor executor) {
this.airship = airship;
this.executor = executor;
this.intent = intent;
this.context = context;
this.notificationInfo = NotificationInfo.fromIntent(intent);
this.actionButtonInfo = NotificationActionButtonInfo.fromIntent(intent);
}
PendingResult<Boolean> process() {
final PendingResult<Boolean> pendingResult = new PendingResult<>();
if (this.intent.getAction() == null || this.notificationInfo == null) {
Logger.error("NotificationIntentProcessor - invalid intent %s", this.intent);
pendingResult.setResult(false);
return pendingResult;
}
Logger.verbose("Processing intent: %s", this.intent.getAction());
String action = this.intent.getAction();
action.hashCode();
if (action.equals(PushManager.ACTION_NOTIFICATION_DISMISSED)) {
onNotificationDismissed();
pendingResult.setResult(true);
} else if (action.equals(PushManager.ACTION_NOTIFICATION_RESPONSE)) {
onNotificationResponse(new Runnable() {
@Override
public void run() {
pendingResult.setResult(true);
}
});
} else {
Logger.error("NotificationIntentProcessor - Invalid intent action: %s", this.intent.getAction());
pendingResult.setResult(false);
}
return pendingResult;
}
private void onNotificationResponse(Runnable completionHandler) {
Logger.info("Notification response: %s, %s", this.notificationInfo, this.actionButtonInfo);
NotificationActionButtonInfo notificationActionButtonInfo = this.actionButtonInfo;
if (notificationActionButtonInfo == null || notificationActionButtonInfo.isForeground()) {
this.airship.getAnalytics().setConversionSendId(this.notificationInfo.getMessage().getSendId());
this.airship.getAnalytics().setConversionMetadata(this.notificationInfo.getMessage().getMetadata());
}
NotificationListener notificationListener = this.airship.getPushManager().getNotificationListener();
if (this.actionButtonInfo != null) {
this.airship.getAnalytics().addEvent(new InteractiveNotificationEvent(this.notificationInfo, this.actionButtonInfo));
NotificationManagerCompat.from(this.context).cancel(this.notificationInfo.getNotificationTag(), this.notificationInfo.getNotificationId());
if (this.actionButtonInfo.isForeground()) {
if (notificationListener == null || !notificationListener.onNotificationForegroundAction(this.notificationInfo, this.actionButtonInfo)) {
launchApplication();
}
} else if (notificationListener != null) {
notificationListener.onNotificationBackgroundAction(this.notificationInfo, this.actionButtonInfo);
}
} else if (notificationListener == null || !notificationListener.onNotificationOpened(this.notificationInfo)) {
launchApplication();
}
Iterator<InternalNotificationListener> it = this.airship.getPushManager().getInternalNotificationListeners().iterator();
while (it.hasNext()) {
it.next().onNotificationResponse(this.notificationInfo, this.actionButtonInfo);
}
runNotificationResponseActions(completionHandler);
}
private void onNotificationDismissed() {
PendingIntent pendingIntent;
Logger.info("Notification dismissed: %s", this.notificationInfo);
if (this.intent.getExtras() != null && (pendingIntent = (PendingIntent) this.intent.getExtras().get(PushManager.EXTRA_NOTIFICATION_DELETE_INTENT)) != null) {
try {
pendingIntent.send();
} catch (PendingIntent.CanceledException unused) {
Logger.debug("Failed to send notification's deleteIntent, already canceled.", new Object[0]);
}
}
NotificationListener notificationListener = this.airship.getPushManager().getNotificationListener();
if (notificationListener != null) {
notificationListener.onNotificationDismissed(this.notificationInfo);
}
}
private void launchApplication() {
PendingIntent pendingIntent;
if (this.intent.getExtras() != null && (pendingIntent = (PendingIntent) this.intent.getExtras().get(PushManager.EXTRA_NOTIFICATION_CONTENT_INTENT)) != null) {
try {
pendingIntent.send();
} catch (PendingIntent.CanceledException unused) {
Logger.debug("Failed to send notification's contentIntent, already canceled.", new Object[0]);
}
} else if (this.airship.getAirshipConfigOptions().autoLaunchApplication) {
Intent launchIntentForPackage = this.context.getPackageManager().getLaunchIntentForPackage(UAirship.getPackageName());
if (launchIntentForPackage != null) {
launchIntentForPackage.setFlags(805306368);
launchIntentForPackage.putExtra(PushManager.EXTRA_PUSH_MESSAGE_BUNDLE, this.notificationInfo.getMessage().getPushBundle());
launchIntentForPackage.setPackage(null);
Logger.info("Starting application's launch intent.", new Object[0]);
this.context.startActivity(launchIntentForPackage);
return;
}
Logger.info("Unable to launch application. Launch intent is unavailable.", new Object[0]);
}
}
private void runNotificationResponseActions(final Runnable completionHandler) {
int i;
Map<String, ActionValue> actions;
Bundle bundle = new Bundle();
bundle.putParcelable(ActionArguments.PUSH_MESSAGE_METADATA, this.notificationInfo.getMessage());
if (this.actionButtonInfo != null) {
String stringExtra = this.intent.getStringExtra(PushManager.EXTRA_NOTIFICATION_BUTTON_ACTIONS_PAYLOAD);
if (UAStringUtil.isEmpty(stringExtra)) {
actions = null;
i = 0;
} else {
actions = parseActionValues(stringExtra);
if (this.actionButtonInfo.getRemoteInput() != null) {
bundle.putBundle(ActionArguments.REMOTE_INPUT_METADATA, this.actionButtonInfo.getRemoteInput());
}
i = this.actionButtonInfo.isForeground() ? 4 : 5;
}
} else {
i = 2;
actions = this.notificationInfo.getMessage().getActions();
}
if (actions == null || actions.isEmpty()) {
completionHandler.run();
} else {
runActions(actions, i, bundle, completionHandler);
}
}
private void runActions(final Map<String, ActionValue> actions, final int situation, final Bundle metadata, final Runnable completionHandler) {
this.executor.execute(new Runnable() {
@Override
public void run() {
final CountDownLatch countDownLatch = new CountDownLatch(actions.size());
for (Map.Entry entry : actions.entrySet()) {
ActionRunRequest.createRequest((String) entry.getKey()).setMetadata(metadata).setSituation(situation).setValue((ActionValue) entry.getValue()).run(new ActionCompletionCallback() {
@Override
public void onFinish(ActionArguments arguments, ActionResult result) {
countDownLatch.countDown();
}
});
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
Logger.error(e, "Failed to wait for actions", new Object[0]);
Thread.currentThread().interrupt();
}
completionHandler.run();
}
});
}
private Map<String, ActionValue> parseActionValues(String payload) {
HashMap hashMap = new HashMap();
try {
JsonMap map = JsonValue.parseString(payload).getMap();
if (map != null) {
Iterator<Map.Entry<String, JsonValue>> it = map.iterator();
while (it.hasNext()) {
Map.Entry<String, JsonValue> next = it.next();
hashMap.put(next.getKey(), new ActionValue(next.getValue()));
}
}
} catch (JsonException e) {
Logger.error(e, "Failed to parse actions for push.", new Object[0]);
}
return hashMap;
}
}