package com.martsnew.tv.service;

import A1.y;
import A6.k;
import B.f;
import B.n;
import O3.e;
import O6.a;
import P6.g;
import Z6.AbstractC0385z;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.IBinder;
import android.os.PowerManager;
import androidx.lifecycle.C0518x;
import androidx.lifecycle.EnumC0509n;
import androidx.lifecycle.InterfaceC0516v;
import androidx.lifecycle.P;
import com.martsnew.tv.R;
import com.martsnew.tv.service.MediaService;
import n4.u0;
import w5.C1706b;
import w5.C1707c;
import w5.C1708d;

/* JADX INFO: loaded from: classes.dex */
public final class MediaService extends Service implements InterfaceC0516v {

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public static final /* synthetic */ int f11121v = 0;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final y f11122q = new y(this);

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final k f11123r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final k f11124s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final k f11125t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final k f11126u;

    public MediaService() {
        final int i = 0;
        this.f11123r = new k(new a(this) { // from class: w5.a

            /* JADX INFO: renamed from: r, reason: collision with root package name */
            public final /* synthetic */ MediaService f18312r;

            {
                this.f18312r = this;
            }

            @Override // O6.a
            public final Object a() {
                MediaService mediaService = this.f18312r;
                switch (i) {
                    case u0.f15495q /* 0 */:
                        int i5 = MediaService.f11121v;
                        Intent intent = new Intent(mediaService, (Class<?>) MediaService.class);
                        intent.setAction("action_stop");
                        PendingIntent service = PendingIntent.getService(mediaService, 0, intent, 67108864);
                        f fVar = new f(mediaService, "media_control_channel");
                        Notification notification = fVar.f484o;
                        notification.icon = R.drawable.ic_play;
                        fVar.f478h = -1;
                        fVar.f485p = true;
                        fVar.c(2, false);
                        fVar.f475e = f.b(mediaService.getString(R.string.channel_name_player));
                        notification.deleteIntent = service;
                        fVar.f477g = service;
                        fVar.c(16, true);
                        return fVar;
                    case 1:
                        int i8 = MediaService.f11121v;
                        return new n(mediaService);
                    case 2:
                        int i9 = MediaService.f11121v;
                        Object systemService = mediaService.getSystemService("power");
                        g.c(systemService, "null cannot be cast to non-null type android.os.PowerManager");
                        return ((PowerManager) systemService).newWakeLock(1, P6.n.a(MediaService.class).c());
                    default:
                        int i10 = MediaService.f11121v;
                        Object systemService2 = mediaService.getSystemService("wifi");
                        g.c(systemService2, "null cannot be cast to non-null type android.net.wifi.WifiManager");
                        WifiManager.WifiLock wifiLockCreateWifiLock = ((WifiManager) systemService2).createWifiLock(Build.VERSION.SDK_INT >= 29 ? 4 : 3, P6.n.a(MediaService.class).c());
                        wifiLockCreateWifiLock.setReferenceCounted(false);
                        return wifiLockCreateWifiLock;
                }
            }
        });
        final int i5 = 1;
        this.f11124s = new k(new a(this) { // from class: w5.a

            /* JADX INFO: renamed from: r, reason: collision with root package name */
            public final /* synthetic */ MediaService f18312r;

            {
                this.f18312r = this;
            }

            @Override // O6.a
            public final Object a() {
                MediaService mediaService = this.f18312r;
                switch (i5) {
                    case u0.f15495q /* 0 */:
                        int i52 = MediaService.f11121v;
                        Intent intent = new Intent(mediaService, (Class<?>) MediaService.class);
                        intent.setAction("action_stop");
                        PendingIntent service = PendingIntent.getService(mediaService, 0, intent, 67108864);
                        f fVar = new f(mediaService, "media_control_channel");
                        Notification notification = fVar.f484o;
                        notification.icon = R.drawable.ic_play;
                        fVar.f478h = -1;
                        fVar.f485p = true;
                        fVar.c(2, false);
                        fVar.f475e = f.b(mediaService.getString(R.string.channel_name_player));
                        notification.deleteIntent = service;
                        fVar.f477g = service;
                        fVar.c(16, true);
                        return fVar;
                    case 1:
                        int i8 = MediaService.f11121v;
                        return new n(mediaService);
                    case 2:
                        int i9 = MediaService.f11121v;
                        Object systemService = mediaService.getSystemService("power");
                        g.c(systemService, "null cannot be cast to non-null type android.os.PowerManager");
                        return ((PowerManager) systemService).newWakeLock(1, P6.n.a(MediaService.class).c());
                    default:
                        int i10 = MediaService.f11121v;
                        Object systemService2 = mediaService.getSystemService("wifi");
                        g.c(systemService2, "null cannot be cast to non-null type android.net.wifi.WifiManager");
                        WifiManager.WifiLock wifiLockCreateWifiLock = ((WifiManager) systemService2).createWifiLock(Build.VERSION.SDK_INT >= 29 ? 4 : 3, P6.n.a(MediaService.class).c());
                        wifiLockCreateWifiLock.setReferenceCounted(false);
                        return wifiLockCreateWifiLock;
                }
            }
        });
        final int i8 = 2;
        this.f11125t = new k(new a(this) { // from class: w5.a

            /* JADX INFO: renamed from: r, reason: collision with root package name */
            public final /* synthetic */ MediaService f18312r;

            {
                this.f18312r = this;
            }

            @Override // O6.a
            public final Object a() {
                MediaService mediaService = this.f18312r;
                switch (i8) {
                    case u0.f15495q /* 0 */:
                        int i52 = MediaService.f11121v;
                        Intent intent = new Intent(mediaService, (Class<?>) MediaService.class);
                        intent.setAction("action_stop");
                        PendingIntent service = PendingIntent.getService(mediaService, 0, intent, 67108864);
                        f fVar = new f(mediaService, "media_control_channel");
                        Notification notification = fVar.f484o;
                        notification.icon = R.drawable.ic_play;
                        fVar.f478h = -1;
                        fVar.f485p = true;
                        fVar.c(2, false);
                        fVar.f475e = f.b(mediaService.getString(R.string.channel_name_player));
                        notification.deleteIntent = service;
                        fVar.f477g = service;
                        fVar.c(16, true);
                        return fVar;
                    case 1:
                        int i82 = MediaService.f11121v;
                        return new n(mediaService);
                    case 2:
                        int i9 = MediaService.f11121v;
                        Object systemService = mediaService.getSystemService("power");
                        g.c(systemService, "null cannot be cast to non-null type android.os.PowerManager");
                        return ((PowerManager) systemService).newWakeLock(1, P6.n.a(MediaService.class).c());
                    default:
                        int i10 = MediaService.f11121v;
                        Object systemService2 = mediaService.getSystemService("wifi");
                        g.c(systemService2, "null cannot be cast to non-null type android.net.wifi.WifiManager");
                        WifiManager.WifiLock wifiLockCreateWifiLock = ((WifiManager) systemService2).createWifiLock(Build.VERSION.SDK_INT >= 29 ? 4 : 3, P6.n.a(MediaService.class).c());
                        wifiLockCreateWifiLock.setReferenceCounted(false);
                        return wifiLockCreateWifiLock;
                }
            }
        });
        final int i9 = 3;
        this.f11126u = new k(new a(this) { // from class: w5.a

            /* JADX INFO: renamed from: r, reason: collision with root package name */
            public final /* synthetic */ MediaService f18312r;

            {
                this.f18312r = this;
            }

            @Override // O6.a
            public final Object a() {
                MediaService mediaService = this.f18312r;
                switch (i9) {
                    case u0.f15495q /* 0 */:
                        int i52 = MediaService.f11121v;
                        Intent intent = new Intent(mediaService, (Class<?>) MediaService.class);
                        intent.setAction("action_stop");
                        PendingIntent service = PendingIntent.getService(mediaService, 0, intent, 67108864);
                        f fVar = new f(mediaService, "media_control_channel");
                        Notification notification = fVar.f484o;
                        notification.icon = R.drawable.ic_play;
                        fVar.f478h = -1;
                        fVar.f485p = true;
                        fVar.c(2, false);
                        fVar.f475e = f.b(mediaService.getString(R.string.channel_name_player));
                        notification.deleteIntent = service;
                        fVar.f477g = service;
                        fVar.c(16, true);
                        return fVar;
                    case 1:
                        int i82 = MediaService.f11121v;
                        return new n(mediaService);
                    case 2:
                        int i92 = MediaService.f11121v;
                        Object systemService = mediaService.getSystemService("power");
                        g.c(systemService, "null cannot be cast to non-null type android.os.PowerManager");
                        return ((PowerManager) systemService).newWakeLock(1, P6.n.a(MediaService.class).c());
                    default:
                        int i10 = MediaService.f11121v;
                        Object systemService2 = mediaService.getSystemService("wifi");
                        g.c(systemService2, "null cannot be cast to non-null type android.net.wifi.WifiManager");
                        WifiManager.WifiLock wifiLockCreateWifiLock = ((WifiManager) systemService2).createWifiLock(Build.VERSION.SDK_INT >= 29 ? 4 : 3, P6.n.a(MediaService.class).c());
                        wifiLockCreateWifiLock.setReferenceCounted(false);
                        return wifiLockCreateWifiLock;
                }
            }
        });
    }

    public static final PowerManager.WakeLock a(MediaService mediaService) {
        Object value = mediaService.f11125t.getValue();
        g.d(value, "getValue(...)");
        return (PowerManager.WakeLock) value;
    }

    @Override // androidx.lifecycle.InterfaceC0516v
    public final e C() {
        return (C0518x) this.f11122q.f363r;
    }

    public final void b() {
        y yVar = this.f11122q;
        yVar.getClass();
        yVar.x(EnumC0509n.ON_CREATE);
        super.onCreate();
    }

    @Override // android.app.Service
    public final IBinder onBind(Intent intent) {
        g.e(intent, "intent");
        y yVar = this.f11122q;
        yVar.getClass();
        yVar.x(EnumC0509n.ON_START);
        return null;
    }

    @Override // android.app.Service
    public final void onCreate() {
        b();
        try {
            startForeground(88, ((f) this.f11123r.getValue()).a());
            AbstractC0385z.r(P.f(this), null, new C1706b(this, null), 3);
        } catch (Exception unused) {
        }
    }

    @Override // android.app.Service
    public final void onDestroy() {
        y yVar = this.f11122q;
        yVar.getClass();
        yVar.x(EnumC0509n.ON_STOP);
        yVar.x(EnumC0509n.ON_DESTROY);
        super.onDestroy();
    }

    @Override // android.app.Service
    public final void onStart(Intent intent, int i) {
        y yVar = this.f11122q;
        yVar.getClass();
        yVar.x(EnumC0509n.ON_START);
        super.onStart(intent, i);
    }

    @Override // android.app.Service
    public final int onStartCommand(Intent intent, int i, int i5) {
        String action = intent != null ? intent.getAction() : null;
        if (action != null) {
            int iHashCode = action.hashCode();
            if (iHashCode != 1583723627) {
                if (iHashCode == 1850778905 && action.equals("action_start")) {
                    try {
                        startForeground(88, ((f) this.f11123r.getValue()).a());
                        AbstractC0385z.r(P.f(this), null, new C1707c(intent, this, null), 3);
                    } catch (Exception unused) {
                        stopSelf();
                    }
                }
            } else if (action.equals("action_stop")) {
                AbstractC0385z.r(P.f(this), null, new C1708d(this, null), 3);
                try {
                    if (Build.VERSION.SDK_INT >= 24) {
                        B.g.j(this);
                    } else {
                        stopForeground(true);
                    }
                } catch (Exception unused2) {
                }
                stopSelf();
            }
        }
        return super.onStartCommand(intent, i, i5);
    }
}
