- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
100 lines
4.2 KiB
Java
100 lines
4.2 KiB
Java
package com.google.firebase.messaging;
|
|
|
|
import android.app.ActivityManager;
|
|
import android.app.KeyguardManager;
|
|
import android.app.NotificationManager;
|
|
import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.os.Process;
|
|
import android.os.SystemClock;
|
|
import android.util.Log;
|
|
import androidx.core.app.NotificationCompat;
|
|
import com.google.android.gms.common.util.PlatformVersion;
|
|
import com.google.android.gms.tasks.Tasks;
|
|
import com.google.firebase.messaging.CommonNotificationBuilder;
|
|
import java.util.List;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class DisplayNotification {
|
|
public final Context context;
|
|
public final ExecutorService networkIoExecutor;
|
|
public final NotificationParams params;
|
|
|
|
public DisplayNotification(Context context, NotificationParams notificationParams, ExecutorService executorService) {
|
|
this.networkIoExecutor = executorService;
|
|
this.context = context;
|
|
this.params = notificationParams;
|
|
}
|
|
|
|
public final boolean isAppForeground() {
|
|
if (((KeyguardManager) this.context.getSystemService("keyguard")).inKeyguardRestrictedInputMode()) {
|
|
return false;
|
|
}
|
|
if (!PlatformVersion.isAtLeastLollipop()) {
|
|
SystemClock.sleep(10L);
|
|
}
|
|
int myPid = Process.myPid();
|
|
List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = ((ActivityManager) this.context.getSystemService("activity")).getRunningAppProcesses();
|
|
if (runningAppProcesses == null) {
|
|
return false;
|
|
}
|
|
for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
|
|
if (runningAppProcessInfo.pid == myPid) {
|
|
return runningAppProcessInfo.importance == 100;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public boolean handleNotification() {
|
|
if (this.params.getBoolean("gcm.n.noui")) {
|
|
return true;
|
|
}
|
|
if (isAppForeground()) {
|
|
return false;
|
|
}
|
|
ImageDownload startImageDownloadInBackground = startImageDownloadInBackground();
|
|
CommonNotificationBuilder.DisplayNotificationInfo createNotificationInfo = CommonNotificationBuilder.createNotificationInfo(this.context, this.params);
|
|
waitForAndApplyImageDownload(createNotificationInfo.notificationBuilder, startImageDownloadInBackground);
|
|
showNotification(createNotificationInfo);
|
|
return true;
|
|
}
|
|
|
|
public final ImageDownload startImageDownloadInBackground() {
|
|
ImageDownload create = ImageDownload.create(this.params.getString("gcm.n.image"));
|
|
if (create != null) {
|
|
create.start(this.networkIoExecutor);
|
|
}
|
|
return create;
|
|
}
|
|
|
|
public final void waitForAndApplyImageDownload(NotificationCompat.Builder builder, ImageDownload imageDownload) {
|
|
if (imageDownload == null) {
|
|
return;
|
|
}
|
|
try {
|
|
Bitmap bitmap = (Bitmap) Tasks.await(imageDownload.getTask(), 5L, TimeUnit.SECONDS);
|
|
builder.setLargeIcon(bitmap);
|
|
builder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap).bigLargeIcon((Bitmap) null));
|
|
} catch (InterruptedException unused) {
|
|
Log.w("FirebaseMessaging", "Interrupted while downloading image, showing notification without it");
|
|
imageDownload.close();
|
|
Thread.currentThread().interrupt();
|
|
} catch (ExecutionException e) {
|
|
Log.w("FirebaseMessaging", "Failed to download image: " + e.getCause());
|
|
} catch (TimeoutException unused2) {
|
|
Log.w("FirebaseMessaging", "Failed to download image in time, showing notification without it");
|
|
imageDownload.close();
|
|
}
|
|
}
|
|
|
|
public final void showNotification(CommonNotificationBuilder.DisplayNotificationInfo displayNotificationInfo) {
|
|
Log.isLoggable("FirebaseMessaging", 3);
|
|
((NotificationManager) this.context.getSystemService("notification")).notify(displayNotificationInfo.tag, displayNotificationInfo.id, displayNotificationInfo.notificationBuilder.build());
|
|
}
|
|
}
|