177 lines
8.4 KiB
Java
177 lines
8.4 KiB
Java
|
package com.discord.utilities.accessibility;
|
||
|
|
||
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||
|
import android.app.Application;
|
||
|
import android.content.ContentResolver;
|
||
|
import android.content.Context;
|
||
|
import android.content.res.Resources;
|
||
|
import android.database.ContentObserver;
|
||
|
import android.net.Uri;
|
||
|
import android.os.Handler;
|
||
|
import android.os.Looper;
|
||
|
import android.provider.Settings;
|
||
|
import android.view.accessibility.AccessibilityManager;
|
||
|
import d0.g;
|
||
|
import d0.z.d.m;
|
||
|
import java.util.EnumSet;
|
||
|
import java.util.List;
|
||
|
import kotlin.Lazy;
|
||
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
||
|
import rx.Observable;
|
||
|
import rx.subjects.BehaviorSubject;
|
||
|
import rx.subjects.SerializedSubject;
|
||
|
/* compiled from: AccessibilityMonitor.kt */
|
||
|
public final class AccessibilityMonitor {
|
||
|
public static final Companion Companion = new Companion(null);
|
||
|
private static final Lazy INSTANCE$delegate = g.lazy(AccessibilityMonitor$Companion$INSTANCE$2.INSTANCE);
|
||
|
private AccessibilityManager accessibilityManager;
|
||
|
private AccessibilityState accessibilityState;
|
||
|
private final SerializedSubject<AccessibilityState, AccessibilityState> accessibilityStateSubject;
|
||
|
private final ContentObserver animationScaleObserver = new AccessibilityMonitor$animationScaleObserver$1(this, new Handler(Looper.getMainLooper()));
|
||
|
private ContentResolver contentResolver;
|
||
|
|
||
|
/* compiled from: AccessibilityMonitor.kt */
|
||
|
public static final class Companion {
|
||
|
private Companion() {
|
||
|
}
|
||
|
|
||
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
||
|
this();
|
||
|
}
|
||
|
|
||
|
public final AccessibilityMonitor getINSTANCE() {
|
||
|
Lazy access$getINSTANCE$cp = AccessibilityMonitor.access$getINSTANCE$cp();
|
||
|
Companion companion = AccessibilityMonitor.Companion;
|
||
|
return (AccessibilityMonitor) access$getINSTANCE$cp.getValue();
|
||
|
}
|
||
|
|
||
|
public final void initialize(Application application) {
|
||
|
m.checkNotNullParameter(application, "application");
|
||
|
getINSTANCE().bindContext(application);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public AccessibilityMonitor() {
|
||
|
AccessibilityState accessibilityState = new AccessibilityState(null, 1, null);
|
||
|
this.accessibilityState = accessibilityState;
|
||
|
this.accessibilityStateSubject = new SerializedSubject<>(BehaviorSubject.l0(accessibilityState));
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ Lazy access$getINSTANCE$cp() {
|
||
|
return INSTANCE$delegate;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ void access$handleReduceMotionUpdated(AccessibilityMonitor accessibilityMonitor) {
|
||
|
accessibilityMonitor.handleReduceMotionUpdated();
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ void access$handleScreenreaderEnabledUpdate(AccessibilityMonitor accessibilityMonitor, boolean z2) {
|
||
|
accessibilityMonitor.handleScreenreaderEnabledUpdate(z2);
|
||
|
}
|
||
|
|
||
|
private final synchronized void handleInitialState(Context context) {
|
||
|
Object systemService = context.getSystemService("accessibility");
|
||
|
if (!(systemService instanceof AccessibilityManager)) {
|
||
|
systemService = null;
|
||
|
}
|
||
|
AccessibilityManager accessibilityManager = (AccessibilityManager) systemService;
|
||
|
if (accessibilityManager != null) {
|
||
|
this.accessibilityManager = accessibilityManager;
|
||
|
if (accessibilityManager == null) {
|
||
|
m.throwUninitializedPropertyAccessException("accessibilityManager");
|
||
|
}
|
||
|
accessibilityManager.addAccessibilityStateChangeListener(new AccessibilityMonitor$handleInitialState$1(this));
|
||
|
AccessibilityManager accessibilityManager2 = this.accessibilityManager;
|
||
|
if (accessibilityManager2 == null) {
|
||
|
m.throwUninitializedPropertyAccessException("accessibilityManager");
|
||
|
}
|
||
|
handleScreenreaderEnabledUpdate(accessibilityManager2.isEnabled());
|
||
|
ContentResolver contentResolver = context.getContentResolver();
|
||
|
m.checkNotNullExpressionValue(contentResolver, "context.contentResolver");
|
||
|
this.contentResolver = contentResolver;
|
||
|
Uri uriFor = Settings.Global.getUriFor("transition_animation_scale");
|
||
|
ContentResolver contentResolver2 = this.contentResolver;
|
||
|
if (contentResolver2 == null) {
|
||
|
m.throwUninitializedPropertyAccessException("contentResolver");
|
||
|
}
|
||
|
contentResolver2.registerContentObserver(uriFor, false, this.animationScaleObserver);
|
||
|
Resources resources = context.getResources();
|
||
|
m.checkNotNullExpressionValue(resources, "context.resources");
|
||
|
handleUIModeUpdate(resources.getConfiguration().uiMode);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private final void handleReduceMotionUpdated() {
|
||
|
EnumSet<AccessibilityFeatureFlags> copyOf = EnumSet.copyOf((EnumSet) this.accessibilityState.getFeatures());
|
||
|
ContentResolver contentResolver = this.contentResolver;
|
||
|
if (contentResolver == null) {
|
||
|
m.throwUninitializedPropertyAccessException("contentResolver");
|
||
|
}
|
||
|
String string = Settings.Global.getString(contentResolver, "transition_animation_scale");
|
||
|
if (m.areEqual(string, "0.0") || m.areEqual(string, "0")) {
|
||
|
copyOf.add(AccessibilityFeatureFlags.REDUCED_MOTION);
|
||
|
} else {
|
||
|
copyOf.remove(AccessibilityFeatureFlags.REDUCED_MOTION);
|
||
|
}
|
||
|
AccessibilityState accessibilityState = this.accessibilityState;
|
||
|
m.checkNotNullExpressionValue(copyOf, "features");
|
||
|
updateAccessibilityState(accessibilityState.copy(copyOf));
|
||
|
}
|
||
|
|
||
|
private final void handleScreenreaderEnabledUpdate(boolean z2) {
|
||
|
EnumSet<AccessibilityFeatureFlags> copyOf = EnumSet.copyOf((EnumSet) this.accessibilityState.getFeatures());
|
||
|
AccessibilityManager accessibilityManager = this.accessibilityManager;
|
||
|
if (accessibilityManager == null) {
|
||
|
m.throwUninitializedPropertyAccessException("accessibilityManager");
|
||
|
}
|
||
|
List<AccessibilityServiceInfo> enabledAccessibilityServiceList = accessibilityManager.getEnabledAccessibilityServiceList(1);
|
||
|
if (z2) {
|
||
|
m.checkNotNullExpressionValue(enabledAccessibilityServiceList, "services");
|
||
|
if (!enabledAccessibilityServiceList.isEmpty()) {
|
||
|
copyOf.add(AccessibilityFeatureFlags.SCREENREADER);
|
||
|
AccessibilityState accessibilityState = this.accessibilityState;
|
||
|
m.checkNotNullExpressionValue(copyOf, "features");
|
||
|
updateAccessibilityState(accessibilityState.copy(copyOf));
|
||
|
}
|
||
|
}
|
||
|
copyOf.remove(AccessibilityFeatureFlags.SCREENREADER);
|
||
|
AccessibilityState accessibilityState = this.accessibilityState;
|
||
|
m.checkNotNullExpressionValue(copyOf, "features");
|
||
|
updateAccessibilityState(accessibilityState.copy(copyOf));
|
||
|
}
|
||
|
|
||
|
private final void handleUIModeUpdate(int i) {
|
||
|
EnumSet<AccessibilityFeatureFlags> copyOf = EnumSet.copyOf((EnumSet) this.accessibilityState.getFeatures());
|
||
|
int i2 = i & 48;
|
||
|
if (i2 == 16) {
|
||
|
copyOf.add(AccessibilityFeatureFlags.PREFERS_COLOR_SCHEME_LIGHT);
|
||
|
copyOf.remove(AccessibilityFeatureFlags.PREFERS_COLOR_SCHEME_DARK);
|
||
|
} else if (i2 != 32) {
|
||
|
copyOf.remove(AccessibilityFeatureFlags.PREFERS_COLOR_SCHEME_LIGHT);
|
||
|
copyOf.remove(AccessibilityFeatureFlags.PREFERS_COLOR_SCHEME_DARK);
|
||
|
} else {
|
||
|
copyOf.add(AccessibilityFeatureFlags.PREFERS_COLOR_SCHEME_DARK);
|
||
|
copyOf.remove(AccessibilityFeatureFlags.PREFERS_COLOR_SCHEME_LIGHT);
|
||
|
}
|
||
|
AccessibilityState accessibilityState = this.accessibilityState;
|
||
|
m.checkNotNullExpressionValue(copyOf, "features");
|
||
|
updateAccessibilityState(accessibilityState.copy(copyOf));
|
||
|
}
|
||
|
|
||
|
private final void updateAccessibilityState(AccessibilityState accessibilityState) {
|
||
|
this.accessibilityState = accessibilityState;
|
||
|
this.accessibilityStateSubject.j.onNext(accessibilityState);
|
||
|
}
|
||
|
|
||
|
public final void bindContext(Context context) {
|
||
|
m.checkNotNullParameter(context, "context");
|
||
|
handleInitialState(context);
|
||
|
}
|
||
|
|
||
|
public final Observable<AccessibilityState> observeAccessibilityState() {
|
||
|
Observable<AccessibilityState> r = this.accessibilityStateSubject.r();
|
||
|
m.checkNotNullExpressionValue(r, "accessibilityStateSubject.distinctUntilChanged()");
|
||
|
return r;
|
||
|
}
|
||
|
}
|