jimu-decompiled/sources/com/google/android/gms/ads/identifier/AdvertisingIdClient.java
2025-05-13 19:24:51 +02:00

325 lines
12 KiB
Java

package com.google.android.gms.ads.identifier;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Log;
import com.baidu.cloud.media.player.BDCloudMediaPlayer;
import com.google.android.gms.common.BlockingServiceConnection;
import com.google.android.gms.common.GoogleApiAvailabilityLight;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.common.GooglePlayServicesUtilLight;
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.common.stats.ConnectionTracker;
import com.google.android.gms.internal.ads_identifier.zze;
import com.google.android.gms.internal.ads_identifier.zzf;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/* loaded from: classes.dex */
public class AdvertisingIdClient {
private final Context mContext;
private BlockingServiceConnection zze;
private zze zzf;
private boolean zzg;
private final Object zzh;
private zza zzi;
private final boolean zzj;
private final long zzk;
public static final class Info {
private final String zzq;
private final boolean zzr;
public Info(String str, boolean z) {
this.zzq = str;
this.zzr = z;
}
public final String getId() {
return this.zzq;
}
public final boolean isLimitAdTrackingEnabled() {
return this.zzr;
}
public final String toString() {
String str = this.zzq;
boolean z = this.zzr;
StringBuilder sb = new StringBuilder(String.valueOf(str).length() + 7);
sb.append("{");
sb.append(str);
sb.append("}");
sb.append(z);
return sb.toString();
}
}
static class zza extends Thread {
private WeakReference<AdvertisingIdClient> a;
private long b;
CountDownLatch c = new CountDownLatch(1);
boolean d = false;
public zza(AdvertisingIdClient advertisingIdClient, long j) {
this.a = new WeakReference<>(advertisingIdClient);
this.b = j;
start();
}
private final void a() {
AdvertisingIdClient advertisingIdClient = this.a.get();
if (advertisingIdClient != null) {
advertisingIdClient.finish();
this.d = true;
}
}
@Override // java.lang.Thread, java.lang.Runnable
public final void run() {
try {
if (this.c.await(this.b, TimeUnit.MILLISECONDS)) {
return;
}
a();
} catch (InterruptedException unused) {
a();
}
}
}
public AdvertisingIdClient(Context context) {
this(context, 30000L, false, false);
}
private AdvertisingIdClient(Context context, long j, boolean z, boolean z2) {
Context applicationContext;
this.zzh = new Object();
Preconditions.a(context);
if (z && (applicationContext = context.getApplicationContext()) != null) {
context = applicationContext;
}
this.mContext = context;
this.zzg = false;
this.zzk = j;
this.zzj = z2;
}
public static Info getAdvertisingIdInfo(Context context) throws IOException, IllegalStateException, GooglePlayServicesNotAvailableException, GooglePlayServicesRepairableException {
zzb zzbVar = new zzb(context);
boolean a = zzbVar.a("gads:ad_id_app_context:enabled", false);
float a2 = zzbVar.a("gads:ad_id_app_context:ping_ratio", 0.0f);
String a3 = zzbVar.a("gads:ad_id_use_shared_preference:experiment_id", "");
AdvertisingIdClient advertisingIdClient = new AdvertisingIdClient(context, -1L, a, zzbVar.a("gads:ad_id_use_persistent_service:enabled", false));
try {
long elapsedRealtime = SystemClock.elapsedRealtime();
advertisingIdClient.zza(false);
Info info = advertisingIdClient.getInfo();
advertisingIdClient.zza(info, a, a2, SystemClock.elapsedRealtime() - elapsedRealtime, a3, null);
return info;
} finally {
}
}
public static boolean getIsAdIdFakeForDebugLogging(Context context) throws IOException, GooglePlayServicesNotAvailableException, GooglePlayServicesRepairableException {
zzb zzbVar = new zzb(context);
AdvertisingIdClient advertisingIdClient = new AdvertisingIdClient(context, -1L, zzbVar.a("gads:ad_id_app_context:enabled", false), zzbVar.a("com.google.android.gms.ads.identifier.service.PERSISTENT_START", false));
try {
advertisingIdClient.zza(false);
return advertisingIdClient.zzb();
} finally {
advertisingIdClient.finish();
}
}
public static void setShouldSkipGmsCoreVersionCheck(boolean z) {
}
private static BlockingServiceConnection zza(Context context, boolean z) throws IOException, GooglePlayServicesNotAvailableException, GooglePlayServicesRepairableException {
try {
context.getPackageManager().getPackageInfo("com.android.vending", 0);
int a = GoogleApiAvailabilityLight.a().a(context, GooglePlayServicesUtilLight.GOOGLE_PLAY_SERVICES_VERSION_CODE);
if (a != 0 && a != 2) {
throw new IOException("Google Play services not available");
}
String str = z ? "com.google.android.gms.ads.identifier.service.PERSISTENT_START" : "com.google.android.gms.ads.identifier.service.START";
BlockingServiceConnection blockingServiceConnection = new BlockingServiceConnection();
Intent intent = new Intent(str);
intent.setPackage("com.google.android.gms");
try {
if (ConnectionTracker.a().a(context, intent, blockingServiceConnection, 1)) {
return blockingServiceConnection;
}
throw new IOException("Connection failure");
} catch (Throwable th) {
throw new IOException(th);
}
} catch (PackageManager.NameNotFoundException unused) {
throw new GooglePlayServicesNotAvailableException(9);
}
}
private static zze zza(Context context, BlockingServiceConnection blockingServiceConnection) throws IOException {
try {
return zzf.a(blockingServiceConnection.a(10000L, TimeUnit.MILLISECONDS));
} catch (InterruptedException unused) {
throw new IOException("Interrupted exception");
} catch (Throwable th) {
throw new IOException(th);
}
}
private final void zza() {
synchronized (this.zzh) {
if (this.zzi != null) {
this.zzi.c.countDown();
try {
this.zzi.join();
} catch (InterruptedException unused) {
}
}
if (this.zzk > 0) {
this.zzi = new zza(this, this.zzk);
}
}
}
private final void zza(boolean z) throws IOException, IllegalStateException, GooglePlayServicesNotAvailableException, GooglePlayServicesRepairableException {
Preconditions.c("Calling this from your main thread can lead to deadlock");
synchronized (this) {
if (this.zzg) {
finish();
}
this.zze = zza(this.mContext, this.zzj);
this.zzf = zza(this.mContext, this.zze);
this.zzg = true;
if (z) {
zza();
}
}
}
private final boolean zza(Info info, boolean z, float f, long j, String str, Throwable th) {
if (Math.random() > f) {
return false;
}
HashMap hashMap = new HashMap();
hashMap.put("app_context", z ? "1" : "0");
if (info != null) {
hashMap.put("limit_ad_tracking", info.isLimitAdTrackingEnabled() ? "1" : "0");
}
if (info != null && info.getId() != null) {
hashMap.put("ad_id_size", Integer.toString(info.getId().length()));
}
if (th != null) {
hashMap.put(BDCloudMediaPlayer.OnNativeInvokeListener.ARG_ERROR, th.getClass().getName());
}
if (str != null && !str.isEmpty()) {
hashMap.put("experiment_id", str);
}
hashMap.put("tag", "AdvertisingIdClient");
hashMap.put("time_spent", Long.toString(j));
new com.google.android.gms.ads.identifier.zza(this, hashMap).start();
return true;
}
private final boolean zzb() throws IOException {
boolean zzc;
Preconditions.c("Calling this from your main thread can lead to deadlock");
synchronized (this) {
if (!this.zzg) {
synchronized (this.zzh) {
if (this.zzi == null || !this.zzi.d) {
throw new IOException("AdvertisingIdClient is not connected.");
}
}
try {
zza(false);
if (!this.zzg) {
throw new IOException("AdvertisingIdClient cannot reconnect.");
}
} catch (Exception e) {
throw new IOException("AdvertisingIdClient cannot reconnect.", e);
}
}
Preconditions.a(this.zze);
Preconditions.a(this.zzf);
try {
zzc = this.zzf.zzc();
} catch (RemoteException e2) {
Log.i("AdvertisingIdClient", "GMS remote exception ", e2);
throw new IOException("Remote exception");
}
}
zza();
return zzc;
}
protected void finalize() throws Throwable {
finish();
super.finalize();
}
public final void finish() {
Preconditions.c("Calling this from your main thread can lead to deadlock");
synchronized (this) {
if (this.mContext == null || this.zze == null) {
return;
}
try {
if (this.zzg) {
ConnectionTracker.a().a(this.mContext, this.zze);
}
} catch (Throwable th) {
Log.i("AdvertisingIdClient", "AdvertisingIdClient unbindService failed.", th);
}
this.zzg = false;
this.zzf = null;
this.zze = null;
}
}
public Info getInfo() throws IOException {
Info info;
Preconditions.c("Calling this from your main thread can lead to deadlock");
synchronized (this) {
if (!this.zzg) {
synchronized (this.zzh) {
if (this.zzi == null || !this.zzi.d) {
throw new IOException("AdvertisingIdClient is not connected.");
}
}
try {
zza(false);
if (!this.zzg) {
throw new IOException("AdvertisingIdClient cannot reconnect.");
}
} catch (Exception e) {
throw new IOException("AdvertisingIdClient cannot reconnect.", e);
}
}
Preconditions.a(this.zze);
Preconditions.a(this.zzf);
try {
info = new Info(this.zzf.getId(), this.zzf.d(true));
} catch (RemoteException e2) {
Log.i("AdvertisingIdClient", "GMS remote exception ", e2);
throw new IOException("Remote exception");
}
}
zza();
return info;
}
public void start() throws IOException, IllegalStateException, GooglePlayServicesNotAvailableException, GooglePlayServicesRepairableException {
zza(true);
}
}