package com.google.firebase.messaging; import android.app.NotificationManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Binder; import android.os.Bundle; import android.util.Log; import androidx.credentials.CredentialManager$$ExternalSyntheticLambda0; import com.google.android.gms.common.util.PlatformVersion; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; import com.google.android.gms.tasks.Tasks; import java.util.concurrent.Executor; /* loaded from: classes3.dex */ public abstract class ProxyNotificationInitializer { public static Task setEnableProxyNotification(Executor executor, final Context context, final boolean z) { if (!PlatformVersion.isAtLeastQ()) { return Tasks.forResult(null); } final TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); executor.execute(new Runnable() { // from class: com.google.firebase.messaging.ProxyNotificationInitializer$$ExternalSyntheticLambda2 @Override // java.lang.Runnable public final void run() { ProxyNotificationInitializer.lambda$setEnableProxyNotification$0(context, z, taskCompletionSource); } }); return taskCompletionSource.getTask(); } public static /* synthetic */ void lambda$setEnableProxyNotification$0(Context context, boolean z, TaskCompletionSource taskCompletionSource) { String notificationDelegate; try { if (!allowedToUse(context)) { Log.e("FirebaseMessaging", "error configuring notification delegate for package " + context.getPackageName()); return; } ProxyNotificationPreferences.setProxyNotificationsInitialized(context, true); NotificationManager notificationManager = (NotificationManager) context.getSystemService(NotificationManager.class); if (z) { notificationManager.setNotificationDelegate("com.google.android.gms"); } else { notificationDelegate = notificationManager.getNotificationDelegate(); if ("com.google.android.gms".equals(notificationDelegate)) { notificationManager.setNotificationDelegate(null); } } } finally { taskCompletionSource.trySetResult(null); } } public static boolean isProxyNotificationEnabled(Context context) { String notificationDelegate; if (!PlatformVersion.isAtLeastQ()) { Log.isLoggable("FirebaseMessaging", 3); return false; } if (!allowedToUse(context)) { Log.e("FirebaseMessaging", "error retrieving notification delegate for package " + context.getPackageName()); return false; } notificationDelegate = ((NotificationManager) context.getSystemService(NotificationManager.class)).getNotificationDelegate(); if (!"com.google.android.gms".equals(notificationDelegate)) { return false; } Log.isLoggable("FirebaseMessaging", 3); return true; } public static boolean shouldEnableProxyNotification(Context context) { ApplicationInfo applicationInfo; Bundle bundle; try { Context applicationContext = context.getApplicationContext(); PackageManager packageManager = applicationContext.getPackageManager(); if (packageManager == null || (applicationInfo = packageManager.getApplicationInfo(applicationContext.getPackageName(), 128)) == null || (bundle = applicationInfo.metaData) == null || !bundle.containsKey("firebase_messaging_notification_delegation_enabled")) { return true; } return applicationInfo.metaData.getBoolean("firebase_messaging_notification_delegation_enabled"); } catch (PackageManager.NameNotFoundException unused) { return true; } } public static void initialize(Context context) { if (ProxyNotificationPreferences.isProxyNotificationInitialized(context)) { return; } setEnableProxyNotification(new CredentialManager$$ExternalSyntheticLambda0(), context, shouldEnableProxyNotification(context)); } public static boolean allowedToUse(Context context) { return Binder.getCallingUid() == context.getApplicationInfo().uid; } }