导航菜单

页面标题

页面副标题

Perplexity v2.48.1 - TtsMediaSessionService.java 源代码

正在查看: Perplexity v2.48.1 应用的 TtsMediaSessionService.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package ai.perplexity.app.android.ui.tts;

import B4.I;
import D1.C0017d;
import D3.u;
import Fc.q;
import G2.p1;
import I4.C0213f;
import Jk.h;
import Lk.c;
import Qa.J;
import Xm.k;
import Z7.C1190d;
import aa.RunnableC1271d;
import ai.perplexity.app.android.ui.main.MainActivity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.service.notification.StatusBarNotification;
import android.text.TextUtils;
import androidx.fragment.app.AbstractC1355z;
import b.C1441d;
import c8.AbstractC1763a;
import c8.AbstractC1764b;
import c8.n;
import c8.y;
import com.google.android.gms.internal.measurement.A1;
import com.mapbox.common.movement.a;
import d.D;
import e3.C1943B;
import e3.C1958a;
import e3.C1963f;
import e3.InterfaceC1944C;
import e3.z;
import e9.C2088d0;
import e9.C2098i0;
import e9.C2110o0;
import e9.C2122v;
import e9.C2123v0;
import e9.H0;
import e9.I0;
import e9.InterfaceC2101k;
import e9.InterfaceC2120u;
import e9.J0;
import e9.K0;
import e9.RunnableC2090e0;
import f5.C2173J;
import f9.T;
import g8.C2449o;
import g8.C2458y;
import ha.g;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.CancellationException;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.SourceDebugExtension;
import n8.Q;
import om.E;
import om.H;
import om.x;
import re.K;
import re.N;
import re.m0;
import rm.j;
import rm.t;
import s.AbstractC3964a;
import um.d;

@Metadata(d1 = {"\u0000\b\n\u0002\u0018\u0002\n\u0002\b\u0003\b\u0007\u0018\u0000B\u0007¢\u0006\u0004\b\u0001\u0010\u0002¨\u0006\u0003"}, d2 = {"Lai/perplexity/app/android/ui/tts/TtsMediaSessionService;", "<init>", "()V", "PerplexityAndroid_v260454(2.48.1)_20250618_122841_release"}, k = 1, mv = {2, 1, 0}, xi = 48)
@SourceDebugExtension
public final class TtsMediaSessionService extends Service implements c {

    public C2098i0 f19565X;

    public J f19566Y;

    public volatile h f19567Z;

    public d f19570t0;

    public C1963f f19571u0;

    public x f19572v0;

    public C2110o0 f19574w0;

    public C2458y f19576x0;

    public J0 f19578z;

    public final Object f19573w = new Object();

    public final Handler f19575x = new Handler(Looper.getMainLooper());

    public final C0213f f19577y = new C0213f(0);

    public final Object f19568r0 = new Object();

    public boolean f19569s0 = false;

    public final Object a() {
        if (this.f19567Z == null) {
            synchronized (this.f19568r0) {
                try {
                    if (this.f19567Z == null) {
                        this.f19567Z = new h(this);
                    }
                } finally {
                }
            }
        }
        return this.f19567Z.a();
    }

    public final void b(C2110o0 c2110o0) {
        C2110o0 c2110o02;
        boolean z10 = true;
        AbstractC1764b.a("session is already released", !c2110o0.f27700a.i());
        synchronized (this.f19573w) {
            c2110o02 = (C2110o0) this.f19577y.get(c2110o0.f27700a.f27783i);
            if (c2110o02 != null && c2110o02 != c2110o0) {
                z10 = false;
            }
            AbstractC1764b.a("Session ID should be unique", z10);
            this.f19577y.put(c2110o0.f27700a.f27783i, c2110o0);
        }
        if (c2110o02 == null) {
            y.I(this.f19575x, new H0(this, d(), c2110o0, 0));
        }
    }

    public final J c() {
        J j10;
        synchronized (this.f19573w) {
            try {
                if (this.f19566Y == null) {
                    this.f19566Y = new J(this, 12);
                }
                j10 = this.f19566Y;
            } catch (Throwable th) {
                throw th;
            }
        }
        return j10;
    }

    public final C2098i0 d() {
        C2098i0 c2098i0;
        synchronized (this.f19573w) {
            try {
                if (this.f19565X == null) {
                    AbstractC1764b.i(getBaseContext(), "Accessing service context before onCreate()");
                    A1 a12 = new A1(getApplicationContext(), 9);
                    AbstractC1764b.g(!a12.x);
                    q qVar = new q();
                    Context context = (Context) a12.y;
                    qVar.x = context;
                    NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
                    AbstractC1764b.h(notificationManager);
                    qVar.y = notificationManager;
                    qVar.w = 2131231243;
                    a12.x = true;
                    this.f19565X = new C2098i0(this, qVar, c());
                }
                c2098i0 = this.f19565X;
            } catch (Throwable th) {
                throw th;
            }
        }
        return c2098i0;
    }

    public final C1963f e() {
        C1963f c1963f = this.f19571u0;
        if (c1963f != null) {
            return c1963f;
        }
        Intrinsics.n("mediaSessionTts");
        throw null;
    }

    public final ArrayList f() {
        ArrayList arrayList;
        synchronized (this.f19573w) {
            arrayList = new ArrayList(this.f19577y.values());
        }
        return arrayList;
    }

    public final boolean g(C2110o0 c2110o0) {
        boolean containsKey;
        synchronized (this.f19573w) {
            containsKey = this.f19577y.containsKey(c2110o0.f27700a.f27783i);
        }
        return containsKey;
    }

    public final void h() {
        super.onCreate();
        synchronized (this.f19573w) {
            this.f19578z = new J0(this);
        }
    }

    public final void i() {
        if (!this.f19569s0) {
            this.f19569s0 = true;
            this.f19571u0 = (C1963f) ((C1441d) ((InterfaceC1944C) a())).f21684a.f21802W3.get();
            this.f19572v0 = AbstractC3964a.b();
        }
        h();
    }

    public final void j() {
        super.onDestroy();
        synchronized (this.f19573w) {
            try {
                J0 j02 = this.f19578z;
                if (j02 != null) {
                    j02.f27317g.clear();
                    j02.f27318h.removeCallbacksAndMessages(null);
                    Iterator it = j02.f27320j.iterator();
                    while (it.hasNext()) {
                        try {
                            ((InterfaceC2101k) it.next()).a();
                        } catch (RemoteException unused) {
                        }
                    }
                    this.f19578z = null;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final int k(Intent intent, int i10, int i11) {
        C2110o0 c2110o0;
        C2110o0 c2110o02;
        if (intent != null) {
            J c10 = c();
            Uri data = intent.getData();
            if (data != null) {
                synchronized (C2110o0.f27698b) {
                    try {
                        Iterator it = C2110o0.f27699c.values().iterator();
                        while (true) {
                            if (!it.hasNext()) {
                                c2110o02 = null;
                                break;
                            }
                            c2110o02 = (C2110o0) it.next();
                            if (Objects.equals(c2110o02.f27700a.f27776b, data)) {
                            }
                        }
                    } finally {
                    }
                }
                c2110o0 = c2110o02;
            } else {
                c2110o0 = null;
            }
            c10.getClass();
            if ("android.intent.action.MEDIA_BUTTON".equals(intent.getAction())) {
                if (c2110o0 == null) {
                    if (TextUtils.isEmpty("android.media.session.MediaController")) {
                        throw new IllegalArgumentException("packageName should be nonempty");
                    }
                    if (Build.VERSION.SDK_INT >= 28) {
                        u.o(-1, "android.media.session.MediaController", -1);
                    }
                    Bundle bundle = Bundle.EMPTY;
                    c2110o0 = this.f19574w0;
                    if (c2110o0 == null) {
                        Intrinsics.n("mediaSession");
                        throw null;
                    }
                    b(c2110o0);
                }
                C2123v0 c2123v0 = c2110o0.f27700a;
                c2123v0.f27786l.post(new RunnableC1271d(29, c2123v0, intent));
                return 1;
            }
            if (c2110o0 != null && "androidx.media3.session.CUSTOM_NOTIFICATION_ACTION".equals(intent.getAction())) {
                Bundle extras = intent.getExtras();
                Object obj = extras != null ? extras.get("androidx.media3.session.EXTRAS_KEY_CUSTOM_NOTIFICATION_ACTION") : null;
                String str = obj instanceof String ? (String) obj : null;
                if (str != null) {
                    Bundle extras2 = intent.getExtras();
                    Object obj2 = extras2 != null ? extras2.get("androidx.media3.session.EXTRAS_KEY_CUSTOM_NOTIFICATION_ACTION_EXTRAS") : null;
                    Bundle bundle2 = obj2 instanceof Bundle ? (Bundle) obj2 : Bundle.EMPTY;
                    C2098i0 d7 = d();
                    C2122v a4 = d7.a(c2110o0);
                    if (a4 != null) {
                        y.I(new Handler(c2110o0.f27700a.f27794t.f27703w.f30384D0), new I(d7, c2110o0, str, bundle2, a4));
                    }
                }
            }
        }
        return 1;
    }

    public final void l(C2110o0 c2110o0, boolean z10) {
        N n5;
        C2098i0 d7 = d();
        if (!d7.f27586w.g(c2110o0) || !d7.c(c2110o0)) {
            int i10 = y.f25148a;
            TtsMediaSessionService ttsMediaSessionService = d7.f27586w;
            if (i10 >= 24) {
                ttsMediaSessionService.stopForeground(1);
            } else {
                ttsMediaSessionService.stopForeground(true);
            }
            d7.f27584u0 = false;
            if (d7.f27583t0 != null) {
                d7.f27590y.f16098b.cancel(null, 1001);
                d7.f27582s0++;
                d7.f27583t0 = null;
                return;
            }
            return;
        }
        int i11 = d7.f27582s0 + 1;
        d7.f27582s0 = i11;
        C2122v a4 = d7.a(c2110o0);
        a4.getClass();
        a4.V();
        InterfaceC2120u interfaceC2120u = a4.f27767x;
        if (interfaceC2120u.w()) {
            n5 = interfaceC2120u.V();
        } else {
            K k9 = N.x;
            n5 = m0.X;
        }
        y.I(new Handler(c2110o0.f27700a.f27794t.f27703w.f30384D0), new RunnableC2090e0(0, d7, c2110o0, n5, new C2088d0(d7, i11, c2110o0), z10));
    }

    public final boolean m(C2110o0 c2110o0, boolean z10) {
        try {
            l(c2110o0, d().b(z10));
            return true;
        } catch (IllegalStateException e10) {
            if (y.f25148a < 31 || !D.w(e10)) {
                throw e10;
            }
            AbstractC1763a.i("MSessionService", "Failed to start foreground", e10);
            this.f19575x.post(new n(this, 15));
            return false;
        }
    }

    public final void n(C2110o0 c2110o0) {
        synchronized (this.f19573w) {
            AbstractC1764b.a("session not found", this.f19577y.containsKey(c2110o0.f27700a.f27783i));
            this.f19577y.remove(c2110o0.f27700a.f27783i);
        }
        y.I(this.f19575x, new I0(0, d(), c2110o0));
    }

    @Override
    public final IBinder onBind(Intent intent) {
        String action;
        J0 j02;
        K0 k02;
        if (intent != null && (action = intent.getAction()) != null) {
            if (action.equals("androidx.media3.session.MediaSessionService")) {
                synchronized (this.f19573w) {
                    j02 = this.f19578z;
                    AbstractC1764b.h(j02);
                }
                return j02;
            }
            if (action.equals("android.media.browse.MediaBrowserService")) {
                if (TextUtils.isEmpty("android.media.session.MediaController")) {
                    throw new IllegalArgumentException("packageName should be nonempty");
                }
                if (Build.VERSION.SDK_INT >= 28) {
                    u.o(-1, "android.media.session.MediaController", -1);
                }
                Bundle bundle = Bundle.EMPTY;
                C2110o0 c2110o0 = this.f19574w0;
                if (c2110o0 == null) {
                    Intrinsics.n("mediaSession");
                    throw null;
                }
                b(c2110o0);
                C2123v0 c2123v0 = c2110o0.f27700a;
                synchronized (c2123v0.f27775a) {
                    try {
                        if (c2123v0.f27798x == null) {
                            T t2 = ((f9.N) c2123v0.f27785k.f27700a.f27782h.f27294k.f29046x).f29024c;
                            K0 k03 = new K0(c2123v0);
                            k03.b(t2);
                            c2123v0.f27798x = k03;
                        }
                        k02 = c2123v0.f27798x;
                    } catch (Throwable th) {
                        throw th;
                    }
                }
                return k02.onBind(new Intent("android.media.browse.MediaBrowserService"));
            }
        }
        return null;
    }

    @Override
    public final void onCreate() {
        boolean isActivity;
        int i10 = 1;
        boolean z10 = false;
        i();
        a aVar = new a(new Rj.y(this, 20), 19);
        C1958a c1958a = new C1958a(this, 0);
        Q q7 = new Q(aVar, new g(27, z10));
        q7.f36611d = new hf.d(27);
        C2449o c2449o = new C2449o(this, c1958a, q7);
        c2449o.b(new C1190d(1, 0, 1, 1, 0), true);
        AbstractC1764b.g(!c2449o.f30360x);
        c2449o.f30349m = true;
        C2458y a4 = c2449o.a();
        a4.prepare();
        a4.I(e().f26498e);
        this.f19576x0 = a4;
        Ni.g gVar = new Ni.g();
        Bundle bundle = new Bundle();
        Bundle bundle2 = new Bundle();
        K k9 = N.x;
        m0 m0Var = m0.X;
        PendingIntent activity = PendingIntent.getActivity(this, 0, new Intent(this, (Class<?>) MainActivity.class), 67108864);
        Intrinsics.g(activity, "getActivity(...)");
        if (y.f25148a >= 31) {
            isActivity = activity.isActivity();
            AbstractC1764b.b(isActivity);
        }
        this.f19574w0 = new C2110o0(this, a4, activity, m0Var, m0Var, m0Var, gVar, bundle, bundle2, new C2173J(new e8.h(this), z10, 25));
        x xVar = this.f19572v0;
        Continuation continuation = null;
        if (xVar == null) {
            Intrinsics.n("uiDispatcher");
            throw null;
        }
        this.f19570t0 = AbstractC1355z.r(om.y.w, xVar.plus(H.c()));
        rm.y yVar = new rm.y(t.A(e().f26494a, new p1(3, continuation, 2)), new e3.y(this, null), 5);
        x xVar2 = this.f19572v0;
        if (xVar2 == null) {
            Intrinsics.n("uiDispatcher");
            throw null;
        }
        j s7 = t.s(yVar, xVar2);
        d dVar = this.f19570t0;
        if (dVar == null) {
            Intrinsics.n("coroutineScope");
            throw null;
        }
        t.v(s7, dVar);
        rm.y yVar2 = new rm.y(e().f26495b, new z(this, null), 5);
        x xVar3 = this.f19572v0;
        if (xVar3 == null) {
            Intrinsics.n("uiDispatcher");
            throw null;
        }
        j s10 = t.s(yVar2, xVar3);
        d dVar2 = this.f19570t0;
        if (dVar2 == null) {
            Intrinsics.n("coroutineScope");
            throw null;
        }
        t.v(s10, dVar2);
        rm.y yVar3 = new rm.y(t.l(new C0017d(e().f26497d, i10)), new C1943B(this, null), 5);
        x xVar4 = this.f19572v0;
        if (xVar4 == null) {
            Intrinsics.n("uiDispatcher");
            throw null;
        }
        j s11 = t.s(yVar3, xVar4);
        d dVar3 = this.f19570t0;
        if (dVar3 != null) {
            t.v(s11, dVar3);
        } else {
            Intrinsics.n("coroutineScope");
            throw null;
        }
    }

    @Override
    public final void onDestroy() {
        j();
        d dVar = this.f19570t0;
        if (dVar == null) {
            Intrinsics.n("coroutineScope");
            throw null;
        }
        E.b(dVar, (CancellationException) null);
        C2110o0 c2110o0 = this.f19574w0;
        if (c2110o0 == null) {
            Intrinsics.n("mediaSession");
            throw null;
        }
        try {
            synchronized (C2110o0.f27698b) {
                C2110o0.f27699c.remove(c2110o0.f27700a.f27783i);
            }
            c2110o0.f27700a.r();
        } catch (Exception unused) {
        }
        C2458y c2458y = this.f19576x0;
        if (c2458y != null) {
            c2458y.release();
        } else {
            Intrinsics.n("player");
            throw null;
        }
    }

    @Override
    public final int onStartCommand(Intent intent, int i10, int i11) {
        NotificationManager notificationManager;
        if (Build.VERSION.SDK_INT < 31 && (notificationManager = (NotificationManager) getSystemService(NotificationManager.class)) != null) {
            StatusBarNotification[] activeNotifications = notificationManager.getActiveNotifications();
            Intrinsics.g(activeNotifications, "getActiveNotifications(...)");
            int length = activeNotifications.length;
            int i12 = 0;
            while (true) {
                if (i12 < length) {
                    StatusBarNotification statusBarNotification = activeNotifications[i12];
                    if (statusBarNotification.getNotification().extras.containsKey("android.mediaSession") || Intrinsics.c(statusBarNotification.getNotification().getChannelId(), "perplexity_temporary_media")) {
                        break;
                    }
                    i12++;
                } else {
                    if (notificationManager.getNotificationChannel("perplexity_temporary_media") == null) {
                        try {
                            notificationManager.createNotificationChannel(new NotificationChannel("perplexity_temporary_media", "Perplexity Media", 2));
                        } catch (RemoteException unused) {
                        }
                    }
                    Notification build = new Notification.Builder(this, "perplexity_temporary_media").setStyle(new Notification.MediaStyle()).setContentTitle("Perplexity Media").setSmallIcon(2131231108).setColor(getColor(2131099673)).build();
                    Intrinsics.g(build, "build(...)");
                    try {
                        if (Build.VERSION.SDK_INT >= 29) {
                            k.h(this, build);
                        } else {
                            startForeground(123, build);
                        }
                    } catch (Exception e10) {
                        Jn.c.a.j(e10, "Failed to manually startForeground: " + e10.getMessage(), new Object[0]);
                    }
                }
            }
        }
        k(intent, i10, i11);
        return 1;
    }

    @Override
    public final void onTaskRemoved(Intent intent) {
        C2458y c2458y = this.f19576x0;
        if (c2458y == null) {
            Intrinsics.n("player");
            throw null;
        }
        if (c2458y.k()) {
            C2458y c2458y2 = this.f19576x0;
            if (c2458y2 == null) {
                Intrinsics.n("player");
                throw null;
            }
            if (c2458y2.H().o() != 0) {
                C2458y c2458y3 = this.f19576x0;
                if (c2458y3 == null) {
                    Intrinsics.n("player");
                    throw null;
                }
                if (c2458y3.d() != 4) {
                    return;
                }
            }
        }
        stopForeground(1);
        stopSelf();
    }
}