- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
154 lines
7.0 KiB
Java
154 lines
7.0 KiB
Java
package com.helpshift.notification;
|
|
|
|
import android.app.Notification;
|
|
import android.app.NotificationChannel;
|
|
import android.app.NotificationManager;
|
|
import android.content.Context;
|
|
import android.media.AudioAttributes;
|
|
import android.net.Uri;
|
|
import androidx.core.app.NotificationCompat;
|
|
import com.helpshift.activities.HSDebugActivity;
|
|
import com.helpshift.activities.HSMainActivity;
|
|
import com.helpshift.concurrency.HSThreadingService;
|
|
import com.helpshift.core.HSContext;
|
|
import com.helpshift.log.HSLogger;
|
|
import com.helpshift.platform.Device;
|
|
import com.helpshift.storage.HSPersistentStorage;
|
|
import com.helpshift.util.ApplicationUtil;
|
|
import com.helpshift.util.Utils;
|
|
import java.lang.ref.WeakReference;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class HSNotificationManager implements CoreNotificationManager {
|
|
public Context context;
|
|
public Device device;
|
|
public WeakReference notificationReceivedCallback;
|
|
public HSPersistentStorage persistentStorage;
|
|
public HSThreadingService threadingService;
|
|
|
|
public HSNotificationManager(Context context, Device device, HSPersistentStorage hSPersistentStorage, HSThreadingService hSThreadingService) {
|
|
this.context = context;
|
|
this.device = device;
|
|
this.persistentStorage = hSPersistentStorage;
|
|
this.threadingService = hSThreadingService;
|
|
}
|
|
|
|
@Override // com.helpshift.notification.CoreNotificationManager
|
|
public void setNotificationChannelId(String str) {
|
|
this.persistentStorage.setNotificationChannelId(str);
|
|
}
|
|
|
|
@Override // com.helpshift.notification.CoreNotificationManager
|
|
public void setNotificationSoundId(int i) {
|
|
this.persistentStorage.setNotificationSoundId(i);
|
|
}
|
|
|
|
@Override // com.helpshift.notification.CoreNotificationManager
|
|
public void setNotificationIcon(int i) {
|
|
this.persistentStorage.setNotificationIcon(i);
|
|
}
|
|
|
|
@Override // com.helpshift.notification.CoreNotificationManager
|
|
public void setNotificationLargeIcon(int i) {
|
|
this.persistentStorage.setNotificationLargeIcon(i);
|
|
}
|
|
|
|
@Override // com.helpshift.notification.CoreNotificationManager
|
|
public void setNotificationReceivedCallback(NotificationReceivedCallback notificationReceivedCallback) {
|
|
this.notificationReceivedCallback = new WeakReference(notificationReceivedCallback);
|
|
}
|
|
|
|
@Override // com.helpshift.notification.CoreNotificationManager
|
|
public void showNotification(final String str, boolean z) {
|
|
HSContext hSContext = HSContext.getInstance();
|
|
if (hSContext.isSdkOpen()) {
|
|
this.threadingService.runOnUIThread(new Runnable() { // from class: com.helpshift.notification.HSNotificationManager.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
NotificationReceivedCallback notificationReceivedCallback = (NotificationReceivedCallback) HSNotificationManager.this.notificationReceivedCallback.get();
|
|
if (notificationReceivedCallback != null) {
|
|
notificationReceivedCallback.onNotificationReceived();
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
if (hSContext.isWebchatUIOpen()) {
|
|
return;
|
|
}
|
|
if (z || this.persistentStorage.getEnableInAppNotification()) {
|
|
this.threadingService.runOnUIThread(new Runnable() { // from class: com.helpshift.notification.HSNotificationManager.2
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
HSNotificationManager.this.showNotificationInternal(str, HSMainActivity.class);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.helpshift.notification.CoreNotificationManager
|
|
public void showDebugLogNotification() {
|
|
this.threadingService.runOnUIThread(new Runnable() { // from class: com.helpshift.notification.HSNotificationManager.3
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
HSNotificationManager.this.showNotificationInternal("Helpshift Debugger: Tap to share debug logs", HSDebugActivity.class);
|
|
}
|
|
});
|
|
}
|
|
|
|
public final void showNotificationInternal(String str, Class cls) {
|
|
NotificationCompat.Builder createNotification = HSNotification.createNotification(this.context, this.device, str, this.persistentStorage.getNotificationIcon(), this.persistentStorage.getNotificationLargeIcon(), this.persistentStorage.getNotificationSoundId(), cls);
|
|
if (createNotification != null) {
|
|
Notification attachChannelId = attachChannelId(createNotification.build(), this.context);
|
|
HSLogger.d("notifMngr", "Notification built, trying to post now.");
|
|
ApplicationUtil.showNotification(this.context, attachChannelId, cls);
|
|
}
|
|
}
|
|
|
|
public final Notification attachChannelId(Notification notification, Context context) {
|
|
if (ApplicationUtil.getTargetSDKVersion(context) < 26) {
|
|
return notification;
|
|
}
|
|
Notification.Builder recoverBuilder = Notification.Builder.recoverBuilder(context, notification);
|
|
recoverBuilder.setChannelId(getActiveNotificationChannel(context));
|
|
return recoverBuilder.build();
|
|
}
|
|
|
|
public final String getActiveNotificationChannel(Context context) {
|
|
String notificationChannelId = this.persistentStorage.getNotificationChannelId();
|
|
if (Utils.isEmpty(notificationChannelId)) {
|
|
ensureDefaultNotificationChannelCreated(context);
|
|
return "In-app Support";
|
|
}
|
|
deleteDefaultNotificationChannel(context);
|
|
return notificationChannelId;
|
|
}
|
|
|
|
public final void deleteDefaultNotificationChannel(Context context) {
|
|
NotificationManager notificationManager = ApplicationUtil.getNotificationManager(context);
|
|
if (notificationManager == null || notificationManager.getNotificationChannel("In-app Support") == null) {
|
|
return;
|
|
}
|
|
notificationManager.deleteNotificationChannel("In-app Support");
|
|
}
|
|
|
|
public final void ensureDefaultNotificationChannelCreated(Context context) {
|
|
NotificationManager notificationManager = ApplicationUtil.getNotificationManager(context);
|
|
if (notificationManager == null || notificationManager.getNotificationChannel("In-app Support") != null) {
|
|
return;
|
|
}
|
|
NotificationChannel notificationChannel = new NotificationChannel("In-app Support", "In-app Support", 3);
|
|
notificationChannel.setDescription("");
|
|
Uri notificationSoundUri = HSNotification.getNotificationSoundUri(context, this.persistentStorage.getNotificationSoundId());
|
|
if (notificationSoundUri != null) {
|
|
notificationChannel.setSound(notificationSoundUri, new AudioAttributes.Builder().build());
|
|
}
|
|
notificationManager.createNotificationChannel(notificationChannel);
|
|
}
|
|
|
|
@Override // com.helpshift.notification.CoreNotificationManager
|
|
public void cancelNotifications() {
|
|
ApplicationUtil.cancelNotification(this.context);
|
|
}
|
|
}
|