package com.discord.app; import android.app.Application; import android.app.Service; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.IBinder; import androidx.core.app.NotificationCompat; import androidx.core.content.ContextCompat; import c.a.d.l0; import c.a.d.n; import c.a.d.n0; import com.discord.stores.StoreConnectionOpen; import com.discord.stores.StoreStream; import com.discord.utilities.analytics.AnalyticsUtils; import com.discord.utilities.color.ColorCompat; import com.discord.utilities.error.Error; import com.discord.utilities.intent.IntentUtils; import com.discord.utilities.intent.RouteHandlers; import com.discord.utilities.logging.Logger; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.utilities.voice.DiscordOverlayService; import d0.g0.s; import d0.g0.t; import d0.t.u; import d0.z.d.m; import d0.z.d.o; import j0.l.e.j; import java.util.List; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.text.MatchResult; import kotlin.text.Regex; import rx.Observable; /* compiled from: DiscordConnectService.kt */ public final class DiscordConnectService extends Service { public static final a i = new a(null); /* compiled from: DiscordConnectService.kt */ public static final class a { public a(DefaultConstructorMarker defaultConstructorMarker) { } public static final void a(a aVar, String str) { AppLog appLog = AppLog.g; String simpleName = DiscordConnectService.class.getSimpleName(); m.checkNotNullExpressionValue(simpleName, "DiscordConnectService::class.java.simpleName"); Logger.i$default(appLog, simpleName, str, null, 4, null); } public final void b(Context context, long j) { m.checkNotNullParameter(context, "context"); Intent intent = IntentUtils.RouteBuilders.INSTANCE.connectVoice(j).setPackage(context.getPackageName()); m.checkNotNullExpressionValue(intent, "IntentUtils.RouteBuilder…kage(context.packageName)"); if (Build.VERSION.SDK_INT >= 26) { context.startForegroundService(intent); } else { context.startService(intent); } } } /* compiled from: DiscordConnectService.kt */ public static final class b extends o implements Function1 { public static final b i = new b(); public b() { super(1); } /* Return type fixed from 'java.lang.Object' to match base method */ @Override // kotlin.jvm.functions.Function1 public Unit invoke(Object obj) { return Unit.a; } } /* compiled from: DiscordConnectService.kt */ public static final class c extends o implements Function0 { public final /* synthetic */ int $startId; public final /* synthetic */ DiscordConnectService this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public c(DiscordConnectService discordConnectService, int i) { super(0); this.this$0 = discordConnectService; this.$startId = i; } /* Return type fixed from 'java.lang.Object' to match base method */ @Override // kotlin.jvm.functions.Function0 /* renamed from: invoke */ public Unit mo1invoke() { a aVar = DiscordConnectService.i; StringBuilder L = c.d.b.a.a.L("Success["); L.append(this.$startId); L.append(']'); a.a(aVar, L.toString()); DiscordConnectService discordConnectService = this.this$0; int i = this.$startId; discordConnectService.stopForeground(true); discordConnectService.stopSelf(i); return Unit.a; } } /* compiled from: DiscordConnectService.kt */ public static final class d extends o implements Function1 { public final /* synthetic */ int $startId; public final /* synthetic */ DiscordConnectService this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public d(DiscordConnectService discordConnectService, int i) { super(1); this.this$0 = discordConnectService; this.$startId = i; } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public Unit invoke(Error error) { Error error2 = error; m.checkNotNullParameter(error2, "it"); error2.setShouldLog(false); a aVar = DiscordConnectService.i; StringBuilder L = c.d.b.a.a.L("Request timeout["); L.append(this.$startId); L.append("]: "); L.append(error2); a.a(aVar, L.toString()); DiscordConnectService discordConnectService = this.this$0; int i = this.$startId; discordConnectService.stopForeground(true); discordConnectService.stopSelf(i); return Unit.a; } } @Override // android.app.Service public IBinder onBind(Intent intent) { throw new IllegalStateException("All my bases are belong to me!"); } @Override // android.app.Service public void onCreate() { super.onCreate(); AppLog appLog = AppLog.g; String simpleName = DiscordConnectService.class.getSimpleName(); m.checkNotNullExpressionValue(simpleName, "DiscordConnectService::class.java.simpleName"); Logger.i$default(appLog, simpleName, "onCreate", null, 4, null); n.f44c.a(this); startForeground(100, new NotificationCompat.Builder(this, "Social").setAutoCancel(true).setOnlyAlertOnce(true).setLocalOnly(true).setSmallIcon(2131231799).setColor(ColorCompat.getThemedColor(this, 2130969007)).setContentTitle(getString(2131887524)).setContentText(getString(2131887531)).build()); StoreStream.Companion companion = StoreStream.Companion; Application application = getApplication(); m.checkNotNullExpressionValue(application, "application"); companion.initialize(application); AnalyticsUtils analyticsUtils = AnalyticsUtils.INSTANCE; Application application2 = getApplication(); m.checkNotNullExpressionValue(application2, "application"); analyticsUtils.initAppOpen(application2); } @Override // android.app.Service public void onDestroy() { AppLog appLog = AppLog.g; String simpleName = DiscordConnectService.class.getSimpleName(); m.checkNotNullExpressionValue(simpleName, "DiscordConnectService::class.java.simpleName"); Logger.i$default(appLog, simpleName, "onDestroy", null, 4, null); n.f44c.b(this); super.onDestroy(); } @Override // android.app.Service public int onStartCommand(Intent intent, int i2, int i3) { Observable observable; Observable observable2; List groupValues; String str; String l = c.d.b.a.a.l("onStartCommand: ", i3); AppLog appLog = AppLog.g; String simpleName = DiscordConnectService.class.getSimpleName(); m.checkNotNullExpressionValue(simpleName, "DiscordConnectService::class.java.simpleName"); Logger.i$default(appLog, simpleName, l, null, 4, null); Uri data = intent != null ? intent.getData() : null; if (data == null || !IntentUtils.INSTANCE.isDiscordAppUri(data)) { String simpleName2 = DiscordConnectService.class.getSimpleName(); m.checkNotNullExpressionValue(simpleName2, "DiscordConnectService::class.java.simpleName"); Logger.i$default(appLog, simpleName2, "Invalid request " + data, null, 4, null); stopForeground(true); stopSelf(i3); return 2; } StoreStream.Companion companion = StoreStream.Companion; String authToken$app_productionBetaRelease = companion.getAuthentication().getAuthToken$app_productionBetaRelease(); if (authToken$app_productionBetaRelease == null || t.isBlank(authToken$app_productionBetaRelease)) { c.a.d.o.g(this, 2131891802, 0, null, 12); observable2 = Observable.w(new IllegalStateException("UNAUTHED")); m.checkNotNullExpressionValue(observable2, "Observable.error(Illegal…ateException(\"UNAUTHED\"))"); } else { c.a.d.r0.b bVar = c.a.d.r0.b.F; Regex regex = c.a.d.r0.b.f47s; String path = data.getPath(); if (path == null) { path = ""; } MatchResult matchEntire = regex.matchEntire(path); Long longOrNull = (matchEntire == null || (groupValues = matchEntire.getGroupValues()) == null || (str = (String) u.getOrNull(groupValues, 1)) == null) ? null : s.toLongOrNull(str); if (matchEntire != null) { companion.getAnalytics().deepLinkReceived(intent != null ? intent : new Intent(), new RouteHandlers.AnalyticsMetadata("connect", null, longOrNull, 2, null)); } if (longOrNull != null) { if (ContextCompat.checkSelfPermission(this, "android.permission.RECORD_AUDIO") != 0) { c.a.d.o.g(this, 2131891927, 0, null, 12); observable2 = Observable.w(new IllegalStateException("Do not have microphone permissions, go to main app")); m.checkNotNullExpressionValue(observable2, "Observable.error(\n …to main app\")\n )"); } else { long longValue = longOrNull.longValue(); String simpleName3 = DiscordConnectService.class.getSimpleName(); m.checkNotNullExpressionValue(simpleName3, "DiscordConnectService::class.java.simpleName"); Logger.i$default(appLog, simpleName3, "Try joining voice channel", null, 4, null); companion.getVoiceChannelSelected().selectVoiceChannel(longValue); Observable x2 = StoreConnectionOpen.observeConnectionOpen$default(companion.getConnectionOpen(), false, 1, null).x(l0.i); m.checkNotNullExpressionValue(x2, "StoreStream\n .get…()\n .filter { it }"); observable2 = ObservableExtensionsKt.takeSingleUntilTimeout$default(x2, 10000, false, 2, null).Y(n0.i); m.checkNotNullExpressionValue(observable2, "isConnectedObs.switchMap…nnected\n }\n }"); } } else if (matchEntire != null) { DiscordOverlayService.Companion.launchForConnect(this); observable = new j(Unit.a); m.checkNotNullExpressionValue(observable, "Observable.just(Unit)"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.takeSingleUntilTimeout$default(observable, 10000, false, 2, null), DiscordConnectService.class, (Context) null, (Function1) null, new d(this, i3), new c(this, i3), (Function0) null, b.i, 38, (Object) null); return 2; } else { observable2 = Observable.w(new IllegalArgumentException("Invalid Request: " + data)); m.checkNotNullExpressionValue(observable2, "Observable.error(Illegal…\"Invalid Request: $uri\"))"); } } observable = observable2; ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.takeSingleUntilTimeout$default(observable, 10000, false, 2, null), DiscordConnectService.class, (Context) null, (Function1) null, new d(this, i3), new c(this, i3), (Function0) null, b.i, 38, (Object) null); return 2; } }