269 lines
14 KiB
Java
269 lines
14 KiB
Java
package com.discord.utilities.voice;
|
|
|
|
import android.app.Application;
|
|
import android.app.Notification;
|
|
import android.app.PendingIntent;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import androidx.core.app.NotificationCompat;
|
|
import c.a.n.c;
|
|
import c.a.n.d;
|
|
import c.a.y.w;
|
|
import c.a.y.z;
|
|
import c.d.b.a.a;
|
|
import com.discord.R;
|
|
import com.discord.app.AppLog;
|
|
import com.discord.overlay.OverlayManager;
|
|
import com.discord.overlay.OverlayService;
|
|
import com.discord.overlay.views.OverlayBubbleWrap;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.utilities.color.ColorCompat;
|
|
import com.discord.utilities.device.DeviceUtils;
|
|
import com.discord.utilities.extensions.PendingIntentExtensionsKt;
|
|
import com.discord.utilities.fcm.NotificationClient;
|
|
import com.discord.utilities.intent.IntentUtils;
|
|
import com.discord.utilities.logging.Logger;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.views.OverlayMenuBubbleDialog;
|
|
import d0.z.d.m;
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.Iterator;
|
|
import java.util.Objects;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
/* compiled from: DiscordOverlayService.kt */
|
|
public final class DiscordOverlayService extends OverlayService {
|
|
private static final String ACTION_CLOSE = "com.discord.actions.OVERLAY_CLOSE";
|
|
private static final String ACTION_OPEN = "com.discord.actions.OVERLAY_OPEN";
|
|
private static final String ACTION_SELECTOR = "com.discord.actions.OVERLAY_SELECTOR";
|
|
private static final String ACTION_VOICE = "com.discord.actions.OVERLAY_VOICE";
|
|
private static final int CLOSE_INTENT_REQ_CODE = 1010;
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final String LOG_TAG = "OverlayService";
|
|
|
|
/* compiled from: DiscordOverlayService.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public static final /* synthetic */ Intent access$createOverlayIntent(Companion companion, Context context, String str) {
|
|
return companion.createOverlayIntent(context, str);
|
|
}
|
|
|
|
private final Intent createOverlayIntent(Context context, String str) {
|
|
return new Intent(str, null, context, DiscordOverlayService.class);
|
|
}
|
|
|
|
private final void tryStartOverlayService(Context context, String str, boolean z2) {
|
|
if (StoreStream.Companion.getUserSettings().getIsMobileOverlayEnabled() || !z2) {
|
|
try {
|
|
context.startService(createOverlayIntent(context, str));
|
|
} catch (Exception e) {
|
|
AppLog.g.v(DiscordOverlayService.LOG_TAG, "Overlay request failed.", e);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static /* synthetic */ void tryStartOverlayService$default(Companion companion, Context context, String str, boolean z2, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
z2 = true;
|
|
}
|
|
companion.tryStartOverlayService(context, str, z2);
|
|
}
|
|
|
|
public final void launchForClose(Context context) {
|
|
m.checkNotNullParameter(context, "context");
|
|
tryStartOverlayService(context, DiscordOverlayService.ACTION_CLOSE, false);
|
|
}
|
|
|
|
public final void launchForConnect(Context context) {
|
|
m.checkNotNullParameter(context, "context");
|
|
StoreStream.Companion companion = StoreStream.Companion;
|
|
if (companion.getUserSettings().getIsMobileOverlayEnabled()) {
|
|
WeakReference weakReference = new WeakReference(context);
|
|
Observable F = ObservableExtensionsKt.takeSingleUntilTimeout$default(companion.getRtcConnection().getConnectionState(), 1000, false, 2, null).F(DiscordOverlayService$Companion$launchForConnect$1.INSTANCE);
|
|
m.checkNotNullExpressionValue(F, "StoreStream\n … }\n }");
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui(F), DiscordOverlayService.class, context, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new DiscordOverlayService$Companion$launchForConnect$2(weakReference), 60, (Object) null);
|
|
return;
|
|
}
|
|
c.a.d.m.g(context, R.string.overlay_mobile_required, 1, null, 8);
|
|
}
|
|
|
|
public final void launchForVoice(Context context) {
|
|
m.checkNotNullParameter(context, "context");
|
|
tryStartOverlayService$default(this, context, DiscordOverlayService.ACTION_VOICE, false, 4, null);
|
|
}
|
|
|
|
public final void launchForVoiceChannelSelect(Context context) {
|
|
m.checkNotNullParameter(context, "context");
|
|
tryStartOverlayService$default(this, context, DiscordOverlayService.ACTION_SELECTOR, false, 4, null);
|
|
}
|
|
}
|
|
|
|
public static final /* synthetic */ OverlayMenuBubbleDialog access$createMenu(DiscordOverlayService discordOverlayService) {
|
|
return discordOverlayService.createMenu();
|
|
}
|
|
|
|
public static final /* synthetic */ OverlayManager access$getOverlayManager$p(DiscordOverlayService discordOverlayService) {
|
|
return discordOverlayService.getOverlayManager();
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleStart$s1927314545(DiscordOverlayService discordOverlayService, Intent intent) {
|
|
super.handleStart(intent);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setOverlayManager$p(DiscordOverlayService discordOverlayService, OverlayManager overlayManager) {
|
|
discordOverlayService.setOverlayManager(overlayManager);
|
|
}
|
|
|
|
private final OverlayMenuBubbleDialog createMenu() {
|
|
Context applicationContext = getApplicationContext();
|
|
m.checkNotNullExpressionValue(applicationContext, "applicationContext");
|
|
OverlayMenuBubbleDialog overlayMenuBubbleDialog = new OverlayMenuBubbleDialog(applicationContext);
|
|
overlayMenuBubbleDialog.getInsetMargins().top = overlayMenuBubbleDialog.getResources().getDimensionPixelOffset(R.dimen.vertical_safe_margin);
|
|
overlayMenuBubbleDialog.setOnDialogClosed(new DiscordOverlayService$createMenu$1(this));
|
|
return overlayMenuBubbleDialog;
|
|
}
|
|
|
|
private final OverlayBubbleWrap createVoiceBubble() {
|
|
int dimensionPixelOffset = getResources().getDimensionPixelOffset(R.dimen.overlay_safe_margin);
|
|
Context applicationContext = getApplicationContext();
|
|
m.checkNotNullExpressionValue(applicationContext, "applicationContext");
|
|
w wVar = new w(applicationContext);
|
|
int i = -dimensionPixelOffset;
|
|
wVar.getInsetMargins().set(i, dimensionPixelOffset, i, dimensionPixelOffset);
|
|
OverlayManager overlayManager = getOverlayManager();
|
|
DiscordOverlayService$createVoiceBubble$1 discordOverlayService$createVoiceBubble$1 = new DiscordOverlayService$createVoiceBubble$1(this, "Active Voice Bubble");
|
|
Objects.requireNonNull(overlayManager);
|
|
m.checkNotNullParameter(wVar, "srcBubble");
|
|
m.checkNotNullParameter("Active Voice Bubble", "anchorViewTag");
|
|
m.checkNotNullParameter(discordOverlayService$createVoiceBubble$1, "menuBubbleProvider");
|
|
wVar.setOnClickListener(new d(overlayManager, discordOverlayService$createVoiceBubble$1, wVar, "Active Voice Bubble"));
|
|
OverlayManager overlayManager2 = getOverlayManager();
|
|
Objects.requireNonNull(overlayManager2);
|
|
m.checkNotNullParameter(wVar, "bubble");
|
|
wVar.setOnTouchListener(overlayManager2.o);
|
|
wVar.setOnMovingStateChanged(new c(overlayManager2, wVar));
|
|
return wVar;
|
|
}
|
|
|
|
private final OverlayBubbleWrap createVoiceSelector() {
|
|
Context applicationContext = getApplicationContext();
|
|
m.checkNotNullExpressionValue(applicationContext, "applicationContext");
|
|
z zVar = new z(applicationContext);
|
|
zVar.setOnDialogClosed(new DiscordOverlayService$createVoiceSelector$1(this));
|
|
return zVar;
|
|
}
|
|
|
|
@Override // com.discord.overlay.OverlayService
|
|
public Notification createNotification(Intent intent) {
|
|
PendingIntent service = PendingIntent.getService(this, 1010, Companion.access$createOverlayIntent(Companion, this, ACTION_CLOSE), PendingIntentExtensionsKt.immutablePendingIntentFlag(134217728));
|
|
Notification build = new NotificationCompat.Builder(this, NotificationClient.NOTIF_CHANNEL_MEDIA_CONNECTIONS).setCategory(NotificationCompat.CATEGORY_SERVICE).setPriority(-2).setOnlyAlertOnce(true).setLocalOnly(true).setSmallIcon(R.drawable.ic_notification_24dp).setColor(ColorCompat.getColor(this, (int) R.color.status_green_600)).setContentTitle(getString(R.string.overlay)).setContentText(getString(R.string.overlay_mobile_toggle_desc)).setOngoing(true).addAction(R.drawable.ic_close_grey_24dp, getString(R.string.close), service).addAction(R.drawable.ic_settings_grey_a60_24dp, getString(R.string.settings), PendingIntent.getActivity(this, 1010, new Intent("android.intent.action.VIEW", IntentUtils.RouteBuilders.Uris.INSTANCE.getSelectSettingsVoice()).setPackage(getPackageName()), PendingIntentExtensionsKt.immutablePendingIntentFlag(134217728))).build();
|
|
m.checkNotNullExpressionValue(build, "NotificationCompat.Build… )\n .build()");
|
|
return build;
|
|
}
|
|
|
|
@Override // com.discord.overlay.OverlayService
|
|
public OverlayBubbleWrap createOverlayBubble(Intent intent) {
|
|
Object obj;
|
|
Object obj2;
|
|
m.checkNotNullParameter(intent, "intent");
|
|
String action = intent.getAction();
|
|
if (action == null) {
|
|
return null;
|
|
}
|
|
int hashCode = action.hashCode();
|
|
if (hashCode != -753952221) {
|
|
if (hashCode != -440170727) {
|
|
if (hashCode == 557534510 && action.equals(ACTION_SELECTOR)) {
|
|
return createVoiceSelector();
|
|
}
|
|
return null;
|
|
} else if (!action.equals(ACTION_OPEN)) {
|
|
return null;
|
|
} else {
|
|
Iterator<T> it = getOverlayManager().j.iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
obj2 = null;
|
|
break;
|
|
}
|
|
obj2 = it.next();
|
|
if (((OverlayBubbleWrap) obj2) instanceof w) {
|
|
break;
|
|
}
|
|
}
|
|
OverlayBubbleWrap overlayBubbleWrap = (OverlayBubbleWrap) obj2;
|
|
if (overlayBubbleWrap == null) {
|
|
return createVoiceBubble();
|
|
}
|
|
overlayBubbleWrap.performClick();
|
|
return null;
|
|
}
|
|
} else if (!action.equals(ACTION_VOICE)) {
|
|
return null;
|
|
} else {
|
|
Iterator<T> it2 = getOverlayManager().j.iterator();
|
|
while (true) {
|
|
if (!it2.hasNext()) {
|
|
obj = null;
|
|
break;
|
|
}
|
|
obj = it2.next();
|
|
if (((OverlayBubbleWrap) obj) instanceof w) {
|
|
break;
|
|
}
|
|
}
|
|
if (((OverlayBubbleWrap) obj) != null) {
|
|
return null;
|
|
}
|
|
return createVoiceBubble();
|
|
}
|
|
}
|
|
|
|
@Override // com.discord.overlay.OverlayService, android.app.Service
|
|
public void onCreate() {
|
|
super.onCreate();
|
|
StoreStream.Companion companion = StoreStream.Companion;
|
|
Application application = getApplication();
|
|
m.checkNotNullExpressionValue(application, "application");
|
|
companion.initialize(application);
|
|
OverlayManager overlayManager = getOverlayManager();
|
|
DiscordOverlayService$onCreate$1 discordOverlayService$onCreate$1 = DiscordOverlayService$onCreate$1.INSTANCE;
|
|
Objects.requireNonNull(overlayManager);
|
|
m.checkNotNullParameter(discordOverlayService$onCreate$1, "<set-?>");
|
|
overlayManager.k = discordOverlayService$onCreate$1;
|
|
OverlayManager overlayManager2 = getOverlayManager();
|
|
DiscordOverlayService$onCreate$2 discordOverlayService$onCreate$2 = new DiscordOverlayService$onCreate$2(this);
|
|
Objects.requireNonNull(overlayManager2);
|
|
m.checkNotNullParameter(discordOverlayService$onCreate$2, "<set-?>");
|
|
overlayManager2.l = discordOverlayService$onCreate$2;
|
|
}
|
|
|
|
@Override // android.app.Service
|
|
public int onStartCommand(Intent intent, int i, int i2) {
|
|
AppLog appLog = AppLog.g;
|
|
StringBuilder L = a.L("onStartCommand: ");
|
|
String str = null;
|
|
L.append(intent != null ? intent.getAction() : null);
|
|
Logger.v$default(appLog, LOG_TAG, L.toString(), null, 4, null);
|
|
if (intent != null) {
|
|
str = intent.getAction();
|
|
}
|
|
if (m.areEqual(str, ACTION_CLOSE) || !DeviceUtils.INSTANCE.canDrawOverlays(this)) {
|
|
stopForeground(true);
|
|
stopSelf(i2);
|
|
return 2;
|
|
}
|
|
Observable<Boolean> Z = StoreStream.Companion.isInitializedObservable().x(DiscordOverlayService$onStartCommand$1.INSTANCE).Z(1);
|
|
m.checkNotNullExpressionValue(Z, "StoreStream.isInitialize….takeFirst { it == true }");
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui(Z), DiscordOverlayService.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new DiscordOverlayService$onStartCommand$2(this, i2, intent), 62, (Object) null);
|
|
return 3;
|
|
}
|
|
}
|