package com.unity3d.services.core.device; import android.annotation.TargetApi; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Binder; import android.os.Build; import android.os.IBinder; import android.os.IInterface; import android.os.Parcel; import com.unity3d.services.core.log.DeviceLog; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @TargetApi(9) /* loaded from: classes2.dex */ public class OpenAdvertisingId { private static final String HW_DEVICE_NAME = "HUAWEI"; private static final String HW_OPEN_ADVERTISING_ID_SERVICE_NAME = "com.uodis.opendevice.aidl.OpenDeviceIdentifierService"; private static OpenAdvertisingId instance; private String openAdvertisingIdentifier = null; private boolean limitedOpenAdTracking = false; private interface HWAdvertisingInfo extends IInterface { public static abstract class HWAdvertisingInfoBinder extends Binder implements HWAdvertisingInfo { private static class HWAdvertisingInfoImplementation implements HWAdvertisingInfo { private final IBinder _binder; HWAdvertisingInfoImplementation(IBinder iBinder) { this._binder = iBinder; } @Override // android.os.IInterface public IBinder asBinder() { return this._binder; } @Override // com.unity3d.services.core.device.OpenAdvertisingId.HWAdvertisingInfo public boolean getEnabled(boolean z10) { Parcel obtain = Parcel.obtain(); Parcel obtain2 = Parcel.obtain(); try { obtain.writeInterfaceToken(OpenAdvertisingId.HW_OPEN_ADVERTISING_ID_SERVICE_NAME); obtain.writeInt(z10 ? 1 : 0); this._binder.transact(2, obtain, obtain2, 0); obtain2.readException(); return obtain2.readInt() != 0; } finally { obtain2.recycle(); obtain.recycle(); } } @Override // com.unity3d.services.core.device.OpenAdvertisingId.HWAdvertisingInfo public String getId() { Parcel obtain = Parcel.obtain(); Parcel obtain2 = Parcel.obtain(); try { obtain.writeInterfaceToken(OpenAdvertisingId.HW_OPEN_ADVERTISING_ID_SERVICE_NAME); this._binder.transact(1, obtain, obtain2, 0); obtain2.readException(); return obtain2.readString(); } finally { obtain2.recycle(); obtain.recycle(); } } } public static HWAdvertisingInfo create(IBinder iBinder) { if (iBinder == null) { return null; } IInterface queryLocalInterface = iBinder.queryLocalInterface(OpenAdvertisingId.HW_OPEN_ADVERTISING_ID_SERVICE_NAME); return (queryLocalInterface == null || !(queryLocalInterface instanceof HWAdvertisingInfo)) ? new HWAdvertisingInfoImplementation(iBinder) : (HWAdvertisingInfo) queryLocalInterface; } @Override // android.os.Binder public boolean onTransact(int i10, Parcel parcel, Parcel parcel2, int i11) { if (i10 == 1) { parcel.enforceInterface(OpenAdvertisingId.HW_OPEN_ADVERTISING_ID_SERVICE_NAME); String id = getId(); parcel2.writeNoException(); parcel2.writeString(id); return true; } if (i10 != 2) { return super.onTransact(i10, parcel, parcel2, i11); } parcel.enforceInterface(OpenAdvertisingId.HW_OPEN_ADVERTISING_ID_SERVICE_NAME); boolean enabled = getEnabled(parcel.readInt() != 0); parcel2.writeNoException(); parcel2.writeInt(enabled ? 1 : 0); return true; } } boolean getEnabled(boolean z10); String getId(); } private class HWAdvertisingServiceConnection implements ServiceConnection { private final BlockingQueue _binderQueue; boolean _consumed; private HWAdvertisingServiceConnection() { this._consumed = false; this._binderQueue = new LinkedBlockingQueue(); } public IBinder getBinder() { if (this._consumed) { throw new IllegalStateException(); } this._consumed = true; return this._binderQueue.take(); } @Override // android.content.ServiceConnection public void onServiceConnected(ComponentName componentName, IBinder iBinder) { try { this._binderQueue.put(iBinder); } catch (InterruptedException unused) { DeviceLog.debug("Couldn't put service to binder que"); Thread.currentThread().interrupt(); } } @Override // android.content.ServiceConnection public void onServiceDisconnected(ComponentName componentName) { } } private void fetchOAId(Context context) { HWAdvertisingServiceConnection hWAdvertisingServiceConnection = new HWAdvertisingServiceConnection(); Intent intent = new Intent("com.uodis.opendevice.OPENIDS_SERVICE"); intent.setPackage("com.huawei.hwid"); try { if (context.bindService(intent, hWAdvertisingServiceConnection, 1)) { try { try { HWAdvertisingInfo create = HWAdvertisingInfo.HWAdvertisingInfoBinder.create(hWAdvertisingServiceConnection.getBinder()); this.openAdvertisingIdentifier = create.getId(); this.limitedOpenAdTracking = create.getEnabled(true); } catch (Exception e10) { DeviceLog.exception("Couldn't get openAdvertising info", e10); } } finally { context.unbindService(hWAdvertisingServiceConnection); } } } catch (Exception e11) { DeviceLog.exception("Couldn't bind to identifier service intent", e11); } } private static OpenAdvertisingId getInstance() { if (instance == null) { instance = new OpenAdvertisingId(); } return instance; } public static boolean getLimitedOpenAdTracking() { return getInstance().limitedOpenAdTracking; } public static String getOpenAdvertisingTrackingId() { return getInstance().openAdvertisingIdentifier; } public static void init(Context context) { if (Build.MANUFACTURER.toUpperCase().equals(HW_DEVICE_NAME)) { getInstance().fetchOAId(context); } } }