discord-jadx/app/src/main/java/com/discord/stores/StoreAudioManagerV2.java

484 lines
22 KiB
Java

package com.discord.stores;
import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import androidx.annotation.VisibleForTesting;
import c.d.b.a.a;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.discord.api.channel.Channel;
import com.discord.api.voice.state.VoiceState;
import com.discord.models.experiments.domain.Experiment;
import com.discord.rtcconnection.RtcConnection;
import com.discord.rtcconnection.audio.DiscordAudioManager;
import com.discord.stores.updates.ObservationDeck;
import com.discord.utilities.voice.PerceptualVolumeUtils;
import d0.t.h0;
import d0.t.n;
import d0.t.o;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
/* compiled from: StoreAudioManagerV2.kt */
public final class StoreAudioManagerV2 extends StoreV2 {
public static final Companion Companion = new Companion(null);
private static final State DEFAULT_STATE;
private static final List<DiscordAudioManager.DeviceTypes> VOICE_ONLY_DEVICE_PRIORITIZATION;
private final StoreAnalytics analyticsStore;
private Handler audioManagerHandler;
private final HandlerThread audioManagerThread = new HandlerThread("AudioManagerThread", -1);
private final StoreChannels channelsStore;
private Context context;
private final Dispatcher dispatcher;
private final StoreExperiments experimentsStore;
private DiscordAudioManager.AudioDevice lastActiveAudioDevice = DiscordAudioManager.b;
private final ObservationDeck observationDeck;
private boolean prevMyVideoOn;
private State state;
private State stateSnapshot;
private final StoreStreamRtcConnection streamRtcConnectionStore;
private final VideoUseDetector videoUseDetector;
private final StoreVoiceChannelSelected voiceChannelSelectedStore;
/* compiled from: StoreAudioManagerV2.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
@VisibleForTesting
public static /* synthetic */ void getDEFAULT_STATE$app_productionBetaRelease$annotations() {
}
public final State getDEFAULT_STATE$app_productionBetaRelease() {
return StoreAudioManagerV2.access$getDEFAULT_STATE$cp();
}
public final List<DiscordAudioManager.DeviceTypes> getVOICE_ONLY_DEVICE_PRIORITIZATION$app_productionBetaRelease() {
return StoreAudioManagerV2.access$getVOICE_ONLY_DEVICE_PRIORITIZATION$cp();
}
}
/* compiled from: StoreAudioManagerV2.kt */
public static final class State {
private DiscordAudioManager.DeviceTypes activeAudioDevice;
private List<DiscordAudioManager.AudioDevice> audioDevices;
public State() {
this(null, null, 3, null);
}
public State(List<DiscordAudioManager.AudioDevice> list, DiscordAudioManager.DeviceTypes deviceTypes) {
m.checkNotNullParameter(list, "audioDevices");
m.checkNotNullParameter(deviceTypes, "activeAudioDevice");
this.audioDevices = list;
this.activeAudioDevice = deviceTypes;
}
/* JADX WARNING: Illegal instructions before constructor call */
public /* synthetic */ State(List list, DiscordAudioManager.DeviceTypes deviceTypes, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(list, (i & 2) != 0 ? DiscordAudioManager.DeviceTypes.INVALID : deviceTypes);
if ((i & 1) != 0) {
DiscordAudioManager discordAudioManager = DiscordAudioManager.d;
list = DiscordAudioManager.f();
}
}
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.stores.StoreAudioManagerV2$State */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ State copy$default(State state, List list, DiscordAudioManager.DeviceTypes deviceTypes, int i, Object obj) {
if ((i & 1) != 0) {
list = state.audioDevices;
}
if ((i & 2) != 0) {
deviceTypes = state.activeAudioDevice;
}
return state.copy(list, deviceTypes);
}
public final List<DiscordAudioManager.AudioDevice> component1() {
return this.audioDevices;
}
public final DiscordAudioManager.DeviceTypes component2() {
return this.activeAudioDevice;
}
public final State copy(List<DiscordAudioManager.AudioDevice> list, DiscordAudioManager.DeviceTypes deviceTypes) {
m.checkNotNullParameter(list, "audioDevices");
m.checkNotNullParameter(deviceTypes, "activeAudioDevice");
return new State(list, deviceTypes);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof State)) {
return false;
}
State state = (State) obj;
return m.areEqual(this.audioDevices, state.audioDevices) && m.areEqual(this.activeAudioDevice, state.activeAudioDevice);
}
public final DiscordAudioManager.DeviceTypes getActiveAudioDevice() {
return this.activeAudioDevice;
}
public final List<DiscordAudioManager.AudioDevice> getAudioDevices() {
return this.audioDevices;
}
public int hashCode() {
List<DiscordAudioManager.AudioDevice> list = this.audioDevices;
int i = 0;
int hashCode = (list != null ? list.hashCode() : 0) * 31;
DiscordAudioManager.DeviceTypes deviceTypes = this.activeAudioDevice;
if (deviceTypes != null) {
i = deviceTypes.hashCode();
}
return hashCode + i;
}
public final void setActiveAudioDevice(DiscordAudioManager.DeviceTypes deviceTypes) {
m.checkNotNullParameter(deviceTypes, "<set-?>");
this.activeAudioDevice = deviceTypes;
}
public final void setAudioDevices(List<DiscordAudioManager.AudioDevice> list) {
m.checkNotNullParameter(list, "<set-?>");
this.audioDevices = list;
}
public String toString() {
StringBuilder P = a.P("State(audioDevices=");
P.append(this.audioDevices);
P.append(", activeAudioDevice=");
P.append(this.activeAudioDevice);
P.append(")");
return P.toString();
}
}
/* compiled from: StoreAudioManagerV2.kt */
public static final class VideoUseDetector {
private final StoreChannels channelsStore;
private final StoreUser usersStore;
private final StoreVoiceStates voiceStatesStore;
public VideoUseDetector(StoreChannels storeChannels, StoreVoiceStates storeVoiceStates, StoreUser storeUser) {
m.checkNotNullParameter(storeChannels, "channelsStore");
m.checkNotNullParameter(storeVoiceStates, "voiceStatesStore");
m.checkNotNullParameter(storeUser, "usersStore");
this.channelsStore = storeChannels;
this.voiceStatesStore = storeVoiceStates;
this.usersStore = storeUser;
}
@StoreThread
private final Map<Long, VoiceState> getVoiceStatesForChannel(long j) {
Channel findChannelByIdInternal$app_productionBetaRelease = this.channelsStore.findChannelByIdInternal$app_productionBetaRelease(j);
Map<Long, VoiceState> map = this.voiceStatesStore.getInternal$app_productionBetaRelease().get(findChannelByIdInternal$app_productionBetaRelease != null ? Long.valueOf(findChannelByIdInternal$app_productionBetaRelease.f()) : null);
if (map == null) {
return h0.emptyMap();
}
LinkedHashMap linkedHashMap = new LinkedHashMap();
for (Map.Entry<Long, VoiceState> entry : map.entrySet()) {
Long a = entry.getValue().a();
if (a != null && a.longValue() == j) {
linkedHashMap.put(entry.getKey(), entry.getValue());
}
}
return linkedHashMap;
}
@StoreThread
public final boolean isAnyoneUsingVideoInChannel(long j) {
Collection<VoiceState> values = getVoiceStatesForChannel(j).values();
if ((values instanceof Collection) && values.isEmpty()) {
return false;
}
for (VoiceState voiceState : values) {
if (AnimatableValueParser.U0(voiceState)) {
return true;
}
}
return false;
}
@StoreThread
public final boolean isMeUsingVideoInChannel(long j) {
VoiceState voiceState = getVoiceStatesForChannel(j).get(Long.valueOf(this.usersStore.getMeInternal$app_productionBetaRelease().getId()));
if (voiceState != null) {
return AnimatableValueParser.U0(voiceState);
}
return false;
}
}
public final /* synthetic */ class WhenMappings {
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
static {
DiscordAudioManager.DeviceTypes.values();
int[] iArr = new int[6];
$EnumSwitchMapping$0 = iArr;
iArr[DiscordAudioManager.DeviceTypes.SPEAKERPHONE.ordinal()] = 1;
}
}
static {
DiscordAudioManager discordAudioManager = DiscordAudioManager.d;
List<DiscordAudioManager.AudioDevice> f = DiscordAudioManager.f();
DiscordAudioManager.DeviceTypes deviceTypes = DiscordAudioManager.DeviceTypes.EARPIECE;
DEFAULT_STATE = new State(f, deviceTypes);
VOICE_ONLY_DEVICE_PRIORITIZATION = n.listOf((Object[]) new DiscordAudioManager.DeviceTypes[]{DiscordAudioManager.DeviceTypes.SPEAKERPHONE, deviceTypes, DiscordAudioManager.DeviceTypes.BLUETOOTH_HEADSET, DiscordAudioManager.DeviceTypes.WIRED_HEADSET});
}
public StoreAudioManagerV2(ObservationDeck observationDeck, Dispatcher dispatcher, StoreVoiceChannelSelected storeVoiceChannelSelected, StoreChannels storeChannels, StoreStreamRtcConnection storeStreamRtcConnection, StoreAnalytics storeAnalytics, VideoUseDetector videoUseDetector, StoreExperiments storeExperiments) {
m.checkNotNullParameter(observationDeck, "observationDeck");
m.checkNotNullParameter(dispatcher, "dispatcher");
m.checkNotNullParameter(storeVoiceChannelSelected, "voiceChannelSelectedStore");
m.checkNotNullParameter(storeChannels, "channelsStore");
m.checkNotNullParameter(storeStreamRtcConnection, "streamRtcConnectionStore");
m.checkNotNullParameter(storeAnalytics, "analyticsStore");
m.checkNotNullParameter(videoUseDetector, "videoUseDetector");
m.checkNotNullParameter(storeExperiments, "experimentsStore");
this.observationDeck = observationDeck;
this.dispatcher = dispatcher;
this.voiceChannelSelectedStore = storeVoiceChannelSelected;
this.channelsStore = storeChannels;
this.streamRtcConnectionStore = storeStreamRtcConnection;
this.analyticsStore = storeAnalytics;
this.videoUseDetector = videoUseDetector;
this.experimentsStore = storeExperiments;
State state = new State(null, null, 3, null);
this.state = state;
this.stateSnapshot = state;
DiscordAudioManager discordAudioManager = DiscordAudioManager.d;
}
public static final /* synthetic */ State access$getAudioManagerState(StoreAudioManagerV2 storeAudioManagerV2) {
return storeAudioManagerV2.getAudioManagerState();
}
public static final /* synthetic */ State access$getDEFAULT_STATE$cp() {
return DEFAULT_STATE;
}
public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreAudioManagerV2 storeAudioManagerV2) {
return storeAudioManagerV2.dispatcher;
}
public static final /* synthetic */ List access$getVOICE_ONLY_DEVICE_PRIORITIZATION$cp() {
return VOICE_ONLY_DEVICE_PRIORITIZATION;
}
public static final /* synthetic */ void access$updateActiveAudioDevice(StoreAudioManagerV2 storeAudioManagerV2, DiscordAudioManager.DeviceTypes deviceTypes) {
storeAudioManagerV2.updateActiveAudioDevice(deviceTypes);
}
public static final /* synthetic */ void access$updateAudioDevices(StoreAudioManagerV2 storeAudioManagerV2, List list) {
storeAudioManagerV2.updateAudioDevices(list);
}
public static final /* synthetic */ void access$updateCurrentMediaVolume(StoreAudioManagerV2 storeAudioManagerV2, int i) {
storeAudioManagerV2.updateCurrentMediaVolume(i);
}
private final State getAudioManagerState() {
return this.stateSnapshot;
}
@StoreThread
private final boolean shouldPrioritizeEarpieceOverSpeaker() {
long selectedVoiceChannelId = this.voiceChannelSelectedStore.getSelectedVoiceChannelId();
Channel channel = this.channelsStore.getChannel(selectedVoiceChannelId);
return channel != null && !AnimatableValueParser.x1(channel) && !this.videoUseDetector.isAnyoneUsingVideoInChannel(selectedVoiceChannelId);
}
@StoreThread
private final void updateActiveAudioDevice(DiscordAudioManager.DeviceTypes deviceTypes) {
State copy$default = State.copy$default(this.state, null, deviceTypes, 1, null);
this.state = copy$default;
if (!(deviceTypes == DiscordAudioManager.DeviceTypes.INVALID || deviceTypes == DiscordAudioManager.DeviceTypes.DEFAULT)) {
this.lastActiveAudioDevice = copy$default.getAudioDevices().get(deviceTypes.getValue());
}
markChanged();
}
@StoreThread
private final void updateAudioDevices(List<DiscordAudioManager.AudioDevice> list) {
this.state = State.copy$default(this.state, list, null, 2, null);
markChanged();
}
private final void updateCurrentMediaVolume(int i) {
DiscordAudioManager discordAudioManager = DiscordAudioManager.d;
this.streamRtcConnectionStore.updateStreamVolume(PerceptualVolumeUtils.INSTANCE.perceptualToAmplitude((((float) i) / ((float) DiscordAudioManager.d().f2168x)) * 300.0f, 300.0f));
}
public final DiscordAudioManager.AudioDevice getLastActiveAudioDevice$app_productionBetaRelease() {
return this.lastActiveAudioDevice;
}
public final State getState$app_productionBetaRelease() {
return this.state;
}
@StoreThread
public final void handleRtcConnectionState(RtcConnection.State state) {
m.checkNotNullParameter(state, "state");
if (m.areEqual(state, RtcConnection.State.f.a)) {
boolean z2 = true;
Experiment userExperiment = this.experimentsStore.getUserExperiment("2021-08_android_speakerphone_default", true);
if (userExperiment == null || userExperiment.getBucket() != 1) {
z2 = false;
}
if (!z2) {
if (shouldPrioritizeEarpieceOverSpeaker()) {
DiscordAudioManager discordAudioManager = DiscordAudioManager.d;
DiscordAudioManager d = DiscordAudioManager.d();
List<DiscordAudioManager.DeviceTypes> list = VOICE_ONLY_DEVICE_PRIORITIZATION;
synchronized (d) {
m.checkNotNullParameter(list, "newPrioritization");
if (!m.areEqual(list, d.D)) {
d.D = list;
d.l();
}
}
} else {
DiscordAudioManager discordAudioManager2 = DiscordAudioManager.d;
DiscordAudioManager d2 = DiscordAudioManager.d();
synchronized (d2) {
List<? extends DiscordAudioManager.DeviceTypes> list2 = d2.D;
List<DiscordAudioManager.DeviceTypes> list3 = DiscordAudioManager.f2166c;
if (!m.areEqual(list2, list3)) {
d2.D = list3;
d2.l();
}
}
}
}
Handler handler = this.audioManagerHandler;
if (handler == null) {
m.throwUninitializedPropertyAccessException("audioManagerHandler");
}
handler.post(StoreAudioManagerV2$handleRtcConnectionState$1.INSTANCE);
} else if ((state instanceof RtcConnection.State.d) && !((RtcConnection.State.d) state).a) {
Handler handler2 = this.audioManagerHandler;
if (handler2 == null) {
m.throwUninitializedPropertyAccessException("audioManagerHandler");
}
handler2.post(StoreAudioManagerV2$handleRtcConnectionState$2.INSTANCE);
}
}
@StoreThread
public final void handleVoiceStatesUpdated() {
boolean isMeUsingVideoInChannel = this.videoUseDetector.isMeUsingVideoInChannel(this.voiceChannelSelectedStore.getSelectedVoiceChannelId());
if (isMeUsingVideoInChannel != this.prevMyVideoOn) {
if (isMeUsingVideoInChannel) {
DiscordAudioManager discordAudioManager = DiscordAudioManager.d;
DiscordAudioManager d = DiscordAudioManager.d();
synchronized (d) {
if (d.r.get(DiscordAudioManager.DeviceTypes.EARPIECE.getValue()).b) {
List<DiscordAudioManager.AudioDevice> list = d.r;
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(list, 10));
for (DiscordAudioManager.AudioDevice audioDevice : list) {
arrayList.add(audioDevice.a.ordinal() != 4 ? DiscordAudioManager.AudioDevice.a(audioDevice, null, false, null, null, 15) : DiscordAudioManager.AudioDevice.a(audioDevice, null, false, null, null, 13));
}
d.r = arrayList;
d.f2167s.j.onNext(arrayList);
d.l();
}
}
} else {
DiscordAudioManager discordAudioManager2 = DiscordAudioManager.d;
DiscordAudioManager d2 = DiscordAudioManager.d();
synchronized (d2) {
if (d2.r.get(DiscordAudioManager.DeviceTypes.EARPIECE.getValue()).b != d2.h) {
List<DiscordAudioManager.AudioDevice> list2 = d2.r;
ArrayList arrayList2 = new ArrayList(o.collectionSizeOrDefault(list2, 10));
for (DiscordAudioManager.AudioDevice audioDevice2 : list2) {
arrayList2.add(audioDevice2.a.ordinal() != 4 ? DiscordAudioManager.AudioDevice.a(audioDevice2, null, false, null, null, 15) : DiscordAudioManager.AudioDevice.a(audioDevice2, null, d2.h, null, null, 13));
}
d2.r = arrayList2;
d2.f2167s.j.onNext(arrayList2);
d2.l();
}
}
}
this.prevMyVideoOn = isMeUsingVideoInChannel;
}
}
public final void init(Application application) {
m.checkNotNullParameter(application, "context");
this.context = application;
if (!this.audioManagerThread.isAlive()) {
this.audioManagerThread.start();
}
Handler handler = new Handler(this.audioManagerThread.getLooper());
this.audioManagerHandler = handler;
if (handler == null) {
m.throwUninitializedPropertyAccessException("audioManagerHandler");
}
handler.post(new StoreAudioManagerV2$init$1(this));
}
public final Observable<State> observeAudioManagerState() {
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreAudioManagerV2$observeAudioManagerState$1(this), 14, null);
}
public final void selectOutputDevice(DiscordAudioManager.DeviceTypes deviceTypes) {
m.checkNotNullParameter(deviceTypes, "device");
DiscordAudioManager.DeviceTypes activeAudioDevice = this.state.getActiveAudioDevice();
Handler handler = this.audioManagerHandler;
if (handler == null) {
m.throwUninitializedPropertyAccessException("audioManagerHandler");
}
handler.post(new StoreAudioManagerV2$selectOutputDevice$1(deviceTypes));
if (deviceTypes != activeAudioDevice) {
this.analyticsStore.trackVoiceAudioOutputModeSelected(this.voiceChannelSelectedStore.getSelectedVoiceChannelId(), activeAudioDevice, deviceTypes);
}
}
public final void setState$app_productionBetaRelease(State state) {
m.checkNotNullParameter(state, "<set-?>");
this.state = state;
}
@Override // com.discord.stores.StoreV2
public void snapshotData() {
super.snapshotData();
List<DiscordAudioManager.AudioDevice> audioDevices = this.state.getAudioDevices();
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(audioDevices, 10));
for (DiscordAudioManager.AudioDevice audioDevice : audioDevices) {
arrayList.add(DiscordAudioManager.AudioDevice.a(audioDevice, null, false, null, null, 15));
}
this.stateSnapshot = this.state.copy(arrayList, this.state.getActiveAudioDevice());
}
public final void toggleSpeakerOutput() {
this.dispatcher.schedule(new StoreAudioManagerV2$toggleSpeakerOutput$1(this));
}
public final void updateMediaVolume(float f) {
Handler handler = this.audioManagerHandler;
if (handler == null) {
m.throwUninitializedPropertyAccessException("audioManagerHandler");
}
handler.post(new StoreAudioManagerV2$updateMediaVolume$1(f));
}
}