- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
136 lines
5.2 KiB
Java
136 lines
5.2 KiB
Java
package com.google.android.gms.common.stats;
|
|
|
|
import android.content.ComponentName;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.ServiceConnection;
|
|
import android.content.pm.PackageManager;
|
|
import android.util.Log;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import com.google.android.gms.common.annotation.KeepForSdk;
|
|
import com.google.android.gms.common.internal.Preconditions;
|
|
import com.google.android.gms.common.internal.zzt;
|
|
import com.google.android.gms.common.util.PlatformVersion;
|
|
import com.google.android.gms.common.wrappers.Wrappers;
|
|
import com.google.errorprone.annotations.ResultIgnorabilityUnspecified;
|
|
import java.util.NoSuchElementException;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.Executor;
|
|
|
|
@KeepForSdk
|
|
/* loaded from: classes2.dex */
|
|
public class ConnectionTracker {
|
|
private static final Object zzb = new Object();
|
|
private static volatile ConnectionTracker zzc;
|
|
|
|
@NonNull
|
|
@VisibleForTesting
|
|
public final ConcurrentHashMap zza = new ConcurrentHashMap();
|
|
|
|
private ConnectionTracker() {
|
|
}
|
|
|
|
@NonNull
|
|
@KeepForSdk
|
|
public static ConnectionTracker getInstance() {
|
|
if (zzc == null) {
|
|
synchronized (zzb) {
|
|
try {
|
|
if (zzc == null) {
|
|
zzc = new ConnectionTracker();
|
|
}
|
|
} finally {
|
|
}
|
|
}
|
|
}
|
|
ConnectionTracker connectionTracker = zzc;
|
|
Preconditions.checkNotNull(connectionTracker);
|
|
return connectionTracker;
|
|
}
|
|
|
|
private static void zzb(Context context, ServiceConnection serviceConnection) {
|
|
try {
|
|
context.unbindService(serviceConnection);
|
|
} catch (IllegalArgumentException | IllegalStateException | NoSuchElementException unused) {
|
|
}
|
|
}
|
|
|
|
private final boolean zzc(Context context, String str, Intent intent, ServiceConnection serviceConnection, int i, boolean z, Executor executor) {
|
|
ComponentName component = intent.getComponent();
|
|
if (component != null) {
|
|
try {
|
|
if ((Wrappers.packageManager(context).getApplicationInfo(component.getPackageName(), 0).flags & 2097152) != 0) {
|
|
Log.w("ConnectionTracker", "Attempted to bind to a service in a STOPPED package.");
|
|
return false;
|
|
}
|
|
} catch (PackageManager.NameNotFoundException unused) {
|
|
}
|
|
}
|
|
if (!zzd(serviceConnection)) {
|
|
return zze(context, intent, serviceConnection, i, executor);
|
|
}
|
|
ServiceConnection serviceConnection2 = (ServiceConnection) this.zza.putIfAbsent(serviceConnection, serviceConnection);
|
|
if (serviceConnection2 != null && serviceConnection != serviceConnection2) {
|
|
Log.w("ConnectionTracker", String.format("Duplicate binding with the same ServiceConnection: %s, %s, %s.", serviceConnection, str, intent.getAction()));
|
|
}
|
|
try {
|
|
boolean zze = zze(context, intent, serviceConnection, i, executor);
|
|
if (zze) {
|
|
return zze;
|
|
}
|
|
return false;
|
|
} finally {
|
|
this.zza.remove(serviceConnection, serviceConnection);
|
|
}
|
|
}
|
|
|
|
private static boolean zzd(ServiceConnection serviceConnection) {
|
|
return !(serviceConnection instanceof zzt);
|
|
}
|
|
|
|
@ResultIgnorabilityUnspecified
|
|
@KeepForSdk
|
|
public boolean bindService(@NonNull Context context, @NonNull Intent intent, @NonNull ServiceConnection serviceConnection, int i) {
|
|
return zzc(context, context.getClass().getName(), intent, serviceConnection, i, true, null);
|
|
}
|
|
|
|
@KeepForSdk
|
|
public void unbindService(@NonNull Context context, @NonNull ServiceConnection serviceConnection) {
|
|
if (!zzd(serviceConnection) || !this.zza.containsKey(serviceConnection)) {
|
|
zzb(context, serviceConnection);
|
|
return;
|
|
}
|
|
try {
|
|
zzb(context, (ServiceConnection) this.zza.get(serviceConnection));
|
|
} finally {
|
|
this.zza.remove(serviceConnection);
|
|
}
|
|
}
|
|
|
|
@KeepForSdk
|
|
public void unbindServiceSafe(@NonNull Context context, @NonNull ServiceConnection serviceConnection) {
|
|
try {
|
|
unbindService(context, serviceConnection);
|
|
} catch (IllegalArgumentException unused) {
|
|
}
|
|
}
|
|
|
|
@ResultIgnorabilityUnspecified
|
|
public final boolean zza(@NonNull Context context, @NonNull String str, @NonNull Intent intent, @NonNull ServiceConnection serviceConnection, int i, Executor executor) {
|
|
return zzc(context, str, intent, serviceConnection, 4225, true, executor);
|
|
}
|
|
|
|
private static final boolean zze(Context context, Intent intent, ServiceConnection serviceConnection, int i, Executor executor) {
|
|
boolean bindService;
|
|
if (executor == null) {
|
|
executor = null;
|
|
}
|
|
if (!PlatformVersion.isAtLeastQ() || executor == null) {
|
|
return context.bindService(intent, serviceConnection, i);
|
|
}
|
|
bindService = context.bindService(intent, i, executor, serviceConnection);
|
|
return bindService;
|
|
}
|
|
}
|