jimu-decompiled/sources/io/fabric/sdk/android/services/common/AdvertisingInfoServiceStrategy.java
2025-05-13 19:24:51 +02:00

159 lines
6.0 KiB
Java

package io.fabric.sdk.android.services.common;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Looper;
import android.os.Parcel;
import android.os.RemoteException;
import io.fabric.sdk.android.Fabric;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
/* loaded from: classes2.dex */
class AdvertisingInfoServiceStrategy implements AdvertisingInfoStrategy {
private final Context a;
private static final class AdvertisingConnection implements ServiceConnection {
private boolean a;
private final LinkedBlockingQueue<IBinder> b;
private AdvertisingConnection() {
this.a = false;
this.b = new LinkedBlockingQueue<>(1);
}
public IBinder a() {
if (this.a) {
Fabric.g().e("Fabric", "getBinder already called");
}
this.a = true;
try {
return this.b.poll(200L, TimeUnit.MILLISECONDS);
} catch (InterruptedException unused) {
return null;
}
}
@Override // android.content.ServiceConnection
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
try {
this.b.put(iBinder);
} catch (InterruptedException unused) {
}
}
@Override // android.content.ServiceConnection
public void onServiceDisconnected(ComponentName componentName) {
this.b.clear();
}
}
private static final class AdvertisingInterface implements IInterface {
private final IBinder a;
public AdvertisingInterface(IBinder iBinder) {
this.a = iBinder;
}
@Override // android.os.IInterface
public IBinder asBinder() {
return this.a;
}
public String getId() throws RemoteException {
String str;
Parcel obtain = Parcel.obtain();
Parcel obtain2 = Parcel.obtain();
try {
try {
obtain.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
this.a.transact(1, obtain, obtain2, 0);
obtain2.readException();
str = obtain2.readString();
} catch (Exception unused) {
Fabric.g().d("Fabric", "Could not get parcel from Google Play Service to capture AdvertisingId");
obtain2.recycle();
obtain.recycle();
str = null;
}
return str;
} finally {
obtain2.recycle();
obtain.recycle();
}
}
public boolean i() throws RemoteException {
Parcel obtain = Parcel.obtain();
Parcel obtain2 = Parcel.obtain();
boolean z = false;
try {
try {
obtain.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
obtain.writeInt(1);
this.a.transact(2, obtain, obtain2, 0);
obtain2.readException();
if (obtain2.readInt() != 0) {
z = true;
}
} catch (Exception unused) {
Fabric.g().d("Fabric", "Could not get parcel from Google Play Service to capture Advertising limitAdTracking");
}
return z;
} finally {
obtain2.recycle();
obtain.recycle();
}
}
}
public AdvertisingInfoServiceStrategy(Context context) {
this.a = context.getApplicationContext();
}
@Override // io.fabric.sdk.android.services.common.AdvertisingInfoStrategy
public AdvertisingInfo a() {
if (Looper.myLooper() == Looper.getMainLooper()) {
Fabric.g().d("Fabric", "AdvertisingInfoServiceStrategy cannot be called on the main thread");
return null;
}
try {
this.a.getPackageManager().getPackageInfo("com.android.vending", 0);
AdvertisingConnection advertisingConnection = new AdvertisingConnection();
Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START");
intent.setPackage("com.google.android.gms");
try {
if (this.a.bindService(intent, advertisingConnection, 1)) {
try {
try {
AdvertisingInterface advertisingInterface = new AdvertisingInterface(advertisingConnection.a());
return new AdvertisingInfo(advertisingInterface.getId(), advertisingInterface.i());
} catch (Exception e) {
Fabric.g().a("Fabric", "Exception in binding to Google Play Service to capture AdvertisingId", e);
this.a.unbindService(advertisingConnection);
}
} finally {
this.a.unbindService(advertisingConnection);
}
} else {
Fabric.g().d("Fabric", "Could not bind to Google Play Service to capture AdvertisingId");
}
} catch (Throwable th) {
Fabric.g().c("Fabric", "Could not bind to Google Play Service to capture AdvertisingId", th);
}
return null;
} catch (PackageManager.NameNotFoundException unused) {
Fabric.g().d("Fabric", "Unable to find Google Play Services package name");
return null;
} catch (Exception e2) {
Fabric.g().c("Fabric", "Unable to determine if Google Play Services is available", e2);
return null;
}
}
}