133 lines
5.3 KiB
Java
133 lines
5.3 KiB
Java
package com.google.firebase.messaging;
|
|
|
|
import C.u;
|
|
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.graphics.drawable.IconCompat;
|
|
import com.google.android.gms.common.util.PlatformVersion;
|
|
import com.google.android.gms.tasks.Tasks;
|
|
import com.google.firebase.messaging.CommonNotificationBuilder;
|
|
import com.google.firebase.messaging.Constants;
|
|
import java.util.Iterator;
|
|
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 */
|
|
class DisplayNotification {
|
|
private static final int IMAGE_DOWNLOAD_TIMEOUT_SECONDS = 5;
|
|
private final Context context;
|
|
private final ExecutorService networkIoExecutor;
|
|
private final NotificationParams params;
|
|
|
|
public DisplayNotification(Context context, NotificationParams notificationParams, ExecutorService executorService) {
|
|
this.networkIoExecutor = executorService;
|
|
this.context = context;
|
|
this.params = notificationParams;
|
|
}
|
|
|
|
private 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) {
|
|
Iterator<ActivityManager.RunningAppProcessInfo> it = runningAppProcesses.iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
break;
|
|
}
|
|
ActivityManager.RunningAppProcessInfo next = it.next();
|
|
if (next.pid == myPid) {
|
|
if (next.importance == 100) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void showNotification(CommonNotificationBuilder.DisplayNotificationInfo displayNotificationInfo) {
|
|
if (Log.isLoggable(Constants.TAG, 3)) {
|
|
Log.d(Constants.TAG, "Showing notification");
|
|
}
|
|
((NotificationManager) this.context.getSystemService("notification")).notify(displayNotificationInfo.tag, displayNotificationInfo.id, displayNotificationInfo.notificationBuilder.a());
|
|
}
|
|
|
|
private ImageDownload startImageDownloadInBackground() {
|
|
ImageDownload create = ImageDownload.create(this.params.getString(Constants.MessageNotificationKeys.IMAGE_URL));
|
|
if (create != null) {
|
|
create.start(this.networkIoExecutor);
|
|
}
|
|
return create;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
/* JADX WARN: Type inference failed for: r3v2, types: [C.r, java.lang.Object, C.v] */
|
|
private void waitForAndApplyImageDownload(u uVar, ImageDownload imageDownload) {
|
|
IconCompat iconCompat;
|
|
IconCompat iconCompat2;
|
|
if (imageDownload == null) {
|
|
return;
|
|
}
|
|
try {
|
|
Bitmap bitmap = (Bitmap) Tasks.await(imageDownload.getTask(), 5L, TimeUnit.SECONDS);
|
|
if (bitmap == null) {
|
|
iconCompat = null;
|
|
} else {
|
|
uVar.getClass();
|
|
iconCompat = new IconCompat(1);
|
|
iconCompat.f2785b = bitmap;
|
|
}
|
|
uVar.h = iconCompat;
|
|
?? obj = new Object();
|
|
if (bitmap == null) {
|
|
iconCompat2 = null;
|
|
} else {
|
|
iconCompat2 = new IconCompat(1);
|
|
iconCompat2.f2785b = bitmap;
|
|
}
|
|
obj.f244b = iconCompat2;
|
|
obj.f245c = null;
|
|
obj.f246d = true;
|
|
uVar.e(obj);
|
|
} catch (InterruptedException unused) {
|
|
Log.w(Constants.TAG, "Interrupted while downloading image, showing notification without it");
|
|
imageDownload.close();
|
|
Thread.currentThread().interrupt();
|
|
} catch (ExecutionException e4) {
|
|
Log.w(Constants.TAG, "Failed to download image: " + e4.getCause());
|
|
} catch (TimeoutException unused2) {
|
|
Log.w(Constants.TAG, "Failed to download image in time, showing notification without it");
|
|
imageDownload.close();
|
|
}
|
|
}
|
|
|
|
public boolean handleNotification() {
|
|
if (this.params.getBoolean(Constants.MessageNotificationKeys.NO_UI)) {
|
|
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;
|
|
}
|
|
}
|